Introducing PyMongo

PyMongo is a library that implements drivers for MongoDB and will allow us to execute commands on our database from our application code. As usual, install it through pip using the following command (note that, similarly to MongoDB, you only need to install this library on the server):

pip install --user pymongo

Now, we can import this library into our application and build our real DBHelper class, implementing all the methods we used in our MockDBHelper class.

Writing the DBHelper class

The last class that we need is the DBHelper class, which will contain all the functions that are required for our application code to talk to our database. This class will use the pymongo library we just installed in order to run MongoDB commands. ...

Get Flask By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.