In the preceding lesson, we built a simple key-value store. The keys were mapped to single values. Document stores like MongoDB, on the other hand, allow us to store more complex information by allowing the keys to be mapped to documents, a structured data model.
Documents can include a variety of data formats such as BSON (Binary JSON), XML, or JSON. For simplicity, we'll implement a document store that manages JSON-like documents.
Python's built-in data structures offer suitable forms for implementing a document store. For instance, dictionaries can represent JSON documents.
Let's create a simple document store. Here, a key maps to a Python dictionary, that represents a document. Each document includes several different fields capturing more detailed information.
Execute the below Python code that implements a simple document store.
xxxxxxxxxx
if __name__ == "__main__":
# Python logic here
document_store = {}
document_store['GOOG'] = {'name': 'Google', 'industry': 'Technology', 'founded': 1998, 'CEO': 'Sundar Pichai'}
document_store['AAPL'] = {'name': 'Apple', 'industry': 'Technology', 'founded': 1976, 'CEO': 'Tim Cook'}
print(document_store)