Created
November 1, 2019 13:32
-
-
Save NMZivkovic/455c167609760c6dac5b8e38f50304f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserRepository(object): | |
def __init__(self): | |
mongoclient = MongoClient('localhost', 27017) | |
#mongoclient = MongoClient('mongodb://localhost:27017') | |
database = mongoclient.local | |
self._users = database.user | |
# Create operations | |
def insert(self, user): | |
return self._users.insert_one(user) | |
def insert_many(self, users): | |
return self._users.insert_many(users) | |
# Read operations | |
def read_all(self): | |
return self._users.find() | |
def read_many(self, conditions): | |
return self._users.find(conditions) | |
def read(self, conditions): | |
return self._users.find_one(conditions) | |
# Update operations | |
def update(self, conditions, new_value): | |
return self._users.update_one(conditions, new_value) | |
def increment_age(self, conditions): | |
return self._users.update_one(conditions, {'$inc' : {'age' : 1}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment