I'm in a class called Client/Server Development.  We are using MongoDB and Jupyter Notebooks to complete our assignments.  We must write a Python program to implement CRUD for use in our database.  I have attached the assignment instructions for the Update and Delete methods.  I already have the Create and Read methods which have been tested and work.  I cannot seem to get Update and Delete to function properly, however.  I deleted what I had for those two sections.  Can I get assistance in how to implement Update and Delete?  Thanks.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I'm in a class called Client/Server Development.  We are using MongoDB and Jupyter Notebooks to complete our assignments.  We must write a Python program to implement CRUD for use in our database.  I have attached the assignment instructions for the Update and Delete methods.  I already have the Create and Read methods which have been tested and work.  I cannot seem to get Update and Delete to function properly, however.  I deleted what I had for those two sections.  Can I get assistance in how to implement Update and Delete?  Thanks.

• 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.
■
O
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.
Transcribed Image Text:• 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. ■ O 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.
1
2
3
4
5
6
7
8
9
10
11
12
13
路14 15 16 17 18 192812232425262728293831323456羽89484123445
20
30
40
44
CRUD.py
from pymongo import MongoClient
from bson.objectid import ObjectId
class AnimalShelter(object):
""" CRUD operations for Animal collection in MongoDB """
def _init__(self, aacuser, admin):
# Initializing the MongoClient. This helps to
# access the MongoDB databases and collections.
self.client = MongoClient('mongodb://%s:%s@localhost: 46703/AAC' % (aacuser, admin))
self.database = self.client['AAC']
# Complete this create method to implement the C in CRUD.
def
create(self, data):
if data is not None:
insert = self.database.animals.insert(data) # data should be dictionary
if insert != 0:
return True
else:
return false
else:
raise Exception ("Nothing to save, data parameter is empty")
# Create method to implement the R in CRUD.
def read(self, criteria-None):
# If criteria is not None then this find will return all rows which matches the criteria
criteria:
if
# {'_id':False} just omits the unique ID of each row
data = self.database.animals.find(criteria, {"_id": False})
else:
# If there is no search criteria then all the rows will be return
data = self.database.animals.find({}, {"_id": False})
assert isinstance(data, object)
return data
# Create method to implement the U in CRUD
# Create method to implement the D in CRUD
Transcribed Image Text:1 2 3 4 5 6 7 8 9 10 11 12 13 路14 15 16 17 18 192812232425262728293831323456羽89484123445 20 30 40 44 CRUD.py from pymongo import MongoClient from bson.objectid import ObjectId class AnimalShelter(object): """ CRUD operations for Animal collection in MongoDB """ def _init__(self, aacuser, admin): # Initializing the MongoClient. This helps to # access the MongoDB databases and collections. self.client = MongoClient('mongodb://%s:%s@localhost: 46703/AAC' % (aacuser, admin)) self.database = self.client['AAC'] # Complete this create method to implement the C in CRUD. def create(self, data): if data is not None: insert = self.database.animals.insert(data) # data should be dictionary if insert != 0: return True else: return false else: raise Exception ("Nothing to save, data parameter is empty") # Create method to implement the R in CRUD. def read(self, criteria-None): # If criteria is not None then this find will return all rows which matches the criteria criteria: if # {'_id':False} just omits the unique ID of each row data = self.database.animals.find(criteria, {"_id": False}) else: # If there is no search criteria then all the rows will be return data = self.database.animals.find({}, {"_id": False}) assert isinstance(data, object) return data # Create method to implement the U in CRUD # Create method to implement the D in CRUD
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

MongoDB does not use SQL.  I'm sorry but was my question even read?

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education