Question: Q . 9 MongoDB ( 2 0 points ) For the products collection in MongoDB, the following four fields are present: name ( String )

Q.9 MongoDB (20 points)
For the products collection in MongoDB, the following four fields are present:
name (String)
category (String)
price (Double)
quantity (Integer)
(1) Implement functions for the following operations:
(a) Insert a new product into the database.
Hint: insert_one method returns a InsertOneResult object, which has a property, inserted_id, that holds the ID of the inserted document
(b) Retrieve all products from the database.
(c) Retrieve a product by its ID.
(d) Update a product's information.
Params
product_id (str): The ID of the product document to update.
updated_data (dict): A dictionary containing updated product information.
(e) Delete a product by its ID.
(2) Insert the six sample documents below into the "products" collection.
\table[[name,category,price,quantity],[Product 1,Electronics,49.99,100],[Product 2,Beauty,29.99,50],[Product 3,Toys,39.99,75],[Product 4,Furniture,99.99,25],[Product 5,Toys,79.99,30],[Product 6,Books,19.99,120]]
(3) Insert the following document into the "products" collection with the function implemented in (1)(a)
Product 7
Beauty
9.99
150
(4) Delete Product 4 in products.
(5) Pretty-print all products.
(6) Group products by the category field then calculate the total price for each category.
Q . 9 MongoDB ( 2 0 points ) For the products

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!