Question: I have already completed the create and read below. I need help with the update and delete part. I have attached my completed work below
I have already completed the create and read below. I need help with the update and delete part. I have attached my completed work below as well. As well as the instructions for the assignment

Next, you must develop a Python module in a PY file, using object-oriented programming methodology, to enable CRUD functionality for the database. To support code reusability, your Python code needs to be importable as a module by other Python scripts. Develop a CRUD class that, when instantiated, provides the following functionality:
- A Create method that inserts a document into a specified MongoDB database and collection
- Input -> argument to function will be a set of key/value pairs in the data type acceptable to the MongoDB driver insert API call.
- Return -> True if successful insert, else False.
- A Read method that queries for document(s) from a specified MongoDB database and specified collection
- Input -> arguments to function should be the key/value lookup pair to use with the MongoDB driver find API call.
- Return -> result in cursor if successful, else MongoDB returned error message.
- An Update method that queries for and changes document(s) from a specified MongoDB database and specified collection
- Input -> arguments to function should be the key/value lookup pair to use with the MongoDB driver find API call. Last argument to function will be a set of key/value pairs in the data type acceptable to the MongoDB driver insert API call.
- Return -> result in JSON format if successful, else MongoDB returned error message.
- A Delete method that queries for and removes document(s) from a specified MongoDB database and specified collection
- Input -> arguments to function should be the key/value lookup pair to use with the MongoDB driver find API call.
- Return -> result in JSON format if successful, else MongoDB returned error message.
from pymongo import MongoClient from bson.objectid import ObjectId class Animal Shelter(object): CRUD operations for Animal collection in MongoDB def init__(self): # Initializing the Mongoclient. This helps to # access the MongoDB databases and collections. self.client = MongoClient('mongodb://localhost:51882') self.database = self.client['AAC'] def create(self, data): # Checks to see if the data is null or empty and returns false in either case if data is not None: if data: self.database.animals.insert_one(data) return True else: return false def read(self, search): # Checks to see if the data is null or empty and returns exception in either case if search is not None: if search: searchResult = self.database. animals.find(search) return searchResult else: exception = "Nothing to search, because search parameter is empty" return exception from AnimalShelter import AnimalShelter # define data data = {"age_upon_outcome": "3 years", "animal id": "A746874", "animal_type": "Cat", "breed": "Domestic Shorthair Mix", "color": "Black/White", "date_of_birth": "2014-04-10", "datetime": "2017-04-11 09:00:00", "monthyear": "2017-04-11T09:00:00", "name": ". "outcome_subtype": "SCRP", "outcome_type": "Transfer", "sex_upon_outcome": "Neutered Male", "location lat": 30.5066578739455, "location long": -97.3408780722188, "age_upon outcome_in_weeks": 156.7678571428 # define search criteria search = {"animal_id": "A746874"} # instantiate an object of Animal Shelter class assignment = Animal Shelter() # call the create method success = assignment.create(data) print (success) # call the read method results = assignment.read (search) print (results) from pymongo import MongoClient from bson.objectid import ObjectId class Animal Shelter(object): CRUD operations for Animal collection in MongoDB def init__(self): # Initializing the Mongoclient. This helps to # access the MongoDB databases and collections. self.client = MongoClient('mongodb://localhost:51882') self.database = self.client['AAC'] def create(self, data): # Checks to see if the data is null or empty and returns false in either case if data is not None: if data: self.database.animals.insert_one(data) return True else: return false def read(self, search): # Checks to see if the data is null or empty and returns exception in either case if search is not None: if search: searchResult = self.database. animals.find(search) return searchResult else: exception = "Nothing to search, because search parameter is empty" return exception from AnimalShelter import AnimalShelter # define data data = {"age_upon_outcome": "3 years", "animal id": "A746874", "animal_type": "Cat", "breed": "Domestic Shorthair Mix", "color": "Black/White", "date_of_birth": "2014-04-10", "datetime": "2017-04-11 09:00:00", "monthyear": "2017-04-11T09:00:00", "name": ". "outcome_subtype": "SCRP", "outcome_type": "Transfer", "sex_upon_outcome": "Neutered Male", "location lat": 30.5066578739455, "location long": -97.3408780722188, "age_upon outcome_in_weeks": 156.7678571428 # define search criteria search = {"animal_id": "A746874"} # instantiate an object of Animal Shelter class assignment = Animal Shelter() # call the create method success = assignment.create(data) print (success) # call the read method results = assignment.read (search) print (results)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
