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.
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. Create a file named dbhelper.py
in the waiter
directory and add the following code:
import pymongo DATABASE = "waitercaller" class DBHelper: def __init__(self): client = pymongo.MongoClient() self.db = client[DATABASE]
This code imports...