Mark As Completed Discussion

As an experienced developer, who unquestionably worked with different database systems before, you might be familiar with MongoDB. It is a document-oriented non-relational database (NoSQL) famous for its scalability and flexibility. As we are about to recreate a primitive version of it, it's essential to know that the core of any document-oriented database, like MongoDB, lies in its documents and collections.

Imagine a document as an equivalent of a row in a SQL database, and a collection as a table. A document is a single record in a collection. A record contains data in fields, just like columns in a SQL database.

Database core setup

In Python, one of the ways we can represent this is using dictionaries and lists. Consider the setup shown in the Python script on your left. We start by implementing a DocumentDB class, which represents our database wrapper. Initially, our database (self.db) is an empty dictionary where keys represent collection names and values are lists of documents in those collections.

The insert method allows us to add documents to specific collections. If the collection doesn't exist, an empty list is added as a placeholder, then the document is appended to that collection.

The find method is a simple implementation of a search feature. It checks every document in a specific collection against a given criteria. If a document fulfils criteria, it is added to the results.

Although our database is extremely simplified, this implementation represents the basic core of a document-oriented database. However, in real production scenarios, other considerations such as concurrency, persistence, validation, etc. need to be taken into account. As we progress with our lessons, we'll keep enhancing this basic structure until we achieve a closer representation of MongoDB, learning key concepts along the way.

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