Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MongoDB is an open - source document - oriented database that is designed to store large scale data. It is categorised as a NoSQL (

MongoDB is an open-source document-oriented database that is designed to store large scale data. It is categorised as a NoSQL (Not only SQL) database because the storage and retrieval of data in the MongoDB is not in the form of tables and querying does not have to be done using SQL.
Based on this document database, write queries in MongoDB for each of the following tasks.
a. Display the customer id and customer name of all customers with a balance of $0.00 and who are not from Christchurch sorted by customer id.
b. Display the customer id, customer name, customer city and customer balance of all customers sorted by customer name in ascending order.
c. Display the product name and product price for every product in the system. Sort the results by product name. Duplicates should be removed.
d.Display the product name and total for all orders made by customer number 1001 sorted by total in descending order.
e. Display the product name and product price for all products that cost greater than or equal to $50.00.
f. For each customer, display the customers name, the number of order and the order total.
g. Display the number of distinct products in the system.
h. Display the product name and the product price for the product with highest price.
i. Display the customer name for all customers who have never ordered a product.
j.Display all cities customers are based in and the number of customers in each city.
k. Display the product name and total for all the product(s) ordered by John.
l. Display the product name and the number of times each product has been ordered.
m. Insert a new customer, (10013,Hans,Dunedin,0.00).
n. Insert a new order for Hans, (Wenlock,40,3,120.00) and update the customer balance for Hans to 120.00.
[{
"_id": {
"$oid": "66456e90222769052b2ade59"
},
"cust_id": "1001",
"cust_name": "John",
"cust_city": "Christchurch",
"cust_balance": 200,
"orders": [
{
"prod_name": "Albertine",
"prod_price": 30,
"prod_qty": 2,
"total": 60
},
{
"prod_name": "Amelia",
"prod_price": 39.9,
"prod_qty": 1,
"total": 39.9
},
{
"prod_name": "Allotria",
"prod_price": 40,
"prod_qty": 2,
"total": 80
}
]
},
{
"_id": {
"$oid": "66456f68222769052b2ade5a"
},
"cust_id": "1002",
"cust_name": "Hannah",
"cust_city": "Christchurch",
"cust_balance": 100,
"orders": [
{
"prod_name": "Ausblush",
"prod_price": 20,
"prod_qty": 1,
"total": 20
},
{
"prod_name": "Ausbord",
"prod_price": 40,
"prod_qty": 2,
"total": 80
}
]
},
{
"_id": {
"$oid": "66456fb7222769052b2ade5b"
},
"cust_id": "1003",
"cust_name": "Rita",
"cust_city": "Christchurch",
"cust_balance": 0,
"orders": [
{
"prod_name": "Ausmas",
"prod_price": 100,
"prod_qty": 1,
"total": 100
},
{
"prod_name": "Chaucer",
"prod_price": 30,
"prod_qty": 2,
"total": 60
}
]
},
{
"_id": {
"$oid": "66457ce1222769052b2ade5c"
},
"cust_id": "1004",
"cust_name": "Milly",
"cust_city": "Wellington",
"cust_balance": 20,
"orders": [
{
"prod_name": "Leander",
"prod_price": 10,
"prod_qty": 5,
"total": 50
},
{
"prod_name": "Lucetta",
"prod_price": 10,
"prod_qty": 1,
"total": 10
},
{
"prod_name": "Chianti",
"prod_price": 30,
"prod_qty": 1,
"total": 30
},
{
"prod_name": "Perditta",
"prod_price": 30,
"prod_qty": 2,
"total": 60
}
]
},
{
"_id": {
"$oid": "66457d0a222769052b2ade5d"
},
"cust_id": "1005",
"cust_name": "Angela",
"cust_city": "Auckland",
"cust_balance": 0,
"orders": [
{
"prod_name": "Chianti",
"prod_price": 30,
"prod_qty": 2,
"total": 60
},
{
"prod_name": "Chaucer",
"prod_price": 30,
"prod_qty": 2,
"total": 60
},
{
"prod_name": "Leander",
"prod_price": 10,
"prod_qty": 10,
"total": 100
}
]
},
{
"_id": {
"$oid": "66457d2a222769052b2ade5e"
},
"cust_id": "1006",
"cust_name": "Barbara",
"cust_city": "Dunedin",
"cust_balance": 200,
"orders": []
},
{
"_id": {
"$oid": "66457d79222769052b2ade5f"
},
"cust_id": "1007",
"cust_name": "Bradley",
"cust_city": "Christchurch",
"cust_balance": 0,
"orders": [
{
"prod_name": "Chaucer",
"prod_price": 30,
"prod_qty": 2,
"total": 60
},
{
"prod_name": "Perditta",
"prod_price": 30,
"prod_qty": 2,
"total": 60
},
{
"prod_name": "Prospero",
"prod_price": 50,
"prod_qty": 3,
"total": 150
}
]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions