Skip to Content
Cloud Native Python
book

Cloud Native Python

by Manish Sethi
July 2017
Intermediate to advanced
374 pages
8h
English
Packt Publishing
Content preview from Cloud Native Python

Initializing the MongoDB database

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python for DevOps

Python for DevOps

Noah Gift, Kennedy Behrman, Alfredo Deza, Grig Gheorghiu
Cloud Native

Cloud Native

Boris Scholl, Trent Swanson, Peter Jausovec

Publisher Resources

ISBN: 9781787129313Supplemental Content