update
This commit is contained in:
@@ -56,4 +56,37 @@ class AnimalShelter(object):
|
||||
data = self.collection.find(criteria)
|
||||
return data
|
||||
except Exception as e:
|
||||
raise Exception(f"Error: {e}")
|
||||
raise Exception(f"Error: {e}")
|
||||
|
||||
def update(self, *args, **kwargs):
|
||||
criteria = kwargs.get('criteria', None)
|
||||
update_one = kwargs.get('once', False)
|
||||
update_type = kwargs.get('update_type', None)
|
||||
data = kwargs.get('data', None)
|
||||
|
||||
|
||||
if update_one:
|
||||
try:
|
||||
self.collection.update_one(criteria, {f'${update_type}': data})
|
||||
except Exception as e:
|
||||
raise Exception(f"Error: {e}")
|
||||
else:
|
||||
try:
|
||||
self.collection.update_many(criteria, {f'${update_type}': data})
|
||||
except Exception as e:
|
||||
raise Exception(f'Error: {e}')
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
criteria = kwargs.get('criteria', None)
|
||||
delete_one = kwargs.get('once', False)
|
||||
|
||||
if delete_one:
|
||||
try:
|
||||
self.collection.delete_one(criteria)
|
||||
except Exception as e:
|
||||
raise Exception(f'Error: {e}')
|
||||
else:
|
||||
try:
|
||||
self.collection.delete_many(criteria)
|
||||
except Exception as e:
|
||||
raise Exception(f'Error: {e}')
|
Reference in New Issue
Block a user