

update ( selector, kudo ) def delete ( self, selector ): return self. create ( kudo ) def update ( self, selector, kudo ): return self. find ( selector ) def create ( self, kudo ): return self. find_all ( selector ) def find ( self, selector ): return self. client = adapter () def find_all ( self, selector ): return self. To export the environment variable, run:Ĭlass Repository ( object ): def _init_ ( self, adapter = None ): self. You might have noticed that the MongoRepository class reads a environment variable MONGO_URL. Notice that all methods explicitly use the pymongo API. deleted_countĪs you can see the MongoRepository class is straightforward, it creates a database connection on its initialization then saves it to a instance variable to be use later by the methods: find_all(), find(), create(), update(), and delete().

modified_count def delete ( self, selector ): return self. insert_one ( kudo ) def update ( self, selector, kudo ): return self. find_one ( selector ) def create ( self, kudo ): return self. find ( selector ) def find ( self, selector ): return self. kudos def find_all ( self, selector ): return self.

Import os from pymongo import MongoClient COLLECTION_NAME = 'kudos' class MongoRepository ( object ): def _init_ ( self ): mongo_url = os. Check the version of Python installed by running the following command:

