animal_shelter

py

School

Southern New Hampshire University *

*We aren’t endorsed by this school

Course

340

Subject

Computer Science

Date

Feb 20, 2024

Type

py

Pages

1

Uploaded by UltraCamelMaster345

Report
from pymongo import MongoClient from bson.objectid import ObjectId class Animal_Shelter (object): """ CURD operations for Animal collection in MongoDB """ def __init__(self, username, password): # Initializes the Mongo Client to help access the MongoDB databases # and collections self.client = MongoClient('mongodb://%s:%s@nv-desktop- services.apporto.com:30335' % ("aacuser", "RtE6")) self.database = self.client['AAC'] #implement the C in CRUD def create(self, data): if data is not None: insert = self.database.animals.insert(data) if insert != 0: return True else: return False else: raise Exception("Nothing to save, because data parameter is empty") #implement the R in CRUD def read(self, criteria=None): if criteria is not None: data = self.database.animals.find(criteria,{"_id": False}) for document in data: print(document) else: data = self.database.animals.find({}, {"_id": False}) return data #implement the U in CRUD def update(self, searchData, updateData): if searchData is not None: result = self.database.animals.update_many(searchData, { "$set": updateData }) else: return "{}" return result.raw_result #implement the D in CRUD def delete(self, deleteData): if deleteData is not None: result = self.database.animals.delete_many(deleteData) else: return "{}" return result.raw_result
Discover more documents: Sign up today!
Unlock a world of knowledge! Explore tailored content for a richer learning experience. Here's what you'll get:
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help