July 2017
Intermediate to advanced
374 pages
8h
English
Previously, when we were creating a database in SQLite3, we needed to create a database and define the schema of tables manually. Since MongoDB is schemaless, we will directly add new documents, and collections will get created automatically. Also, in this case, we will initialize the database using Python only.
Before we add new documents into MongoDB, we need to install the Python driver for it, that is, pymongo.
Add the pymongo driver to requirements.txt, and then install it using the pip package manager as follows:
$echo "pymongo==3.4.0" >> requirements.txt $ pip install -r requirements.txt
Once it is installed, we will import it by adding the following line to app.py:
from pymongo import MongoClient ...