Mark As Completed Discussion

As you're an experienced engineer, you know that once we've defined our database and the type of documents it'll store, the next step is storing these documents.

In a Document-Oriented Database, storing a document involves adding it to the collection of documents. For this, we'll usually be implementing a method named add or insert. This method will receive a document (a dictionary, in our Python case) and add it to the database, usually generating an ID to reference it later.

On the other hand, since our documents are dictionary-like objects, they can contain nested dictionaries, thus introducing hierarchical data. This is an advantage over traditional SQL databases where storing such hierarchical data can be a little bit complex.

Let's consider an example where we store our earlier created profile of a software engineer to our Document-Oriented Database:

In the Python code snippet below we define our 'database' as a dictionary. We then present a function add_document(db, document) which adds a document to the database and returns a generated ID for the inserted document.

PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment