Project 2
a)
db.customer.insertMany([
{"_id":1,
"First_Name":"Junie",
"Last_Name":"Solomn",
"Gender":"Female",
"DOB":"2/20/1997",
"Email_id":"[email protected]",
"Mobile_no":9876543210,
"Address":"Chennai"},
{"_id":2,
"First_Name":"Denaries",
"Last_Name":"Targerian",
"Gender":"Female",
"DOB":12/20/19970,
"Email_id":"[email protected]",
"Mobile_no":9876543210,
"Address":"Chennai"}
]);

b)
db.customer.updateOne({_id:1},{$set :{ "Type":"Normal"}})
db.customer.updateOne({_id:2},{$set :{ "Type":"Premium"}})

c)
db.products.insertMany([
{
"_id":1,
"Poduct_Name":"Mobile Phone",
"Availablity":"yes",
},
{
"_id":2,
"Poduct_Name":"kitchen",
"Availablity":"yes"
}
])
d)
db.products.updateMany(
{_id:1},
{$set:
{
"Catagory":"Electronics",
"Brands":"i phone"
}
})
db.products.updateMany(
{_id:2},
{$set:
{
"Catagory":"Home Appliances",
"Brands":"Butterfly",
}
}
)

e)
db.products.updateMany(
{_id:1},
{$set:
{
"Sub Catagory":"SmartPhones"
}
})
db.products.updateMany(
{_id:2},
{$set:
{
"Sub Catagory":"Kitchen"
}
}
)

f)
db.products.updateMany(
{_id:1},
{$set:
{
"tags":"phones,Mobiles"
}
})
db.products.updateMany(
{_id:2},
{$set:
{
"tags":"Homes , Applianes, utensils"
}
}
)

g)
db.cart.insertMany([
{
"_id":1,
"Payment_to_product":"pending"
},
{
"_id":2,
"Payment_to_product":"completed"
}
]);
h)
db.admin.insertMany([
{
"_id":1,
"Product":"Laptops",
"SubCatagory":"Electronics",
"Tags":"Laptop, tab"
},
{
"_id":2,
"Product":"Headphnes"
"SubCatagory" :"Electronics",
"Tags":"Headset,earphones"
}
]);
i)
db.seller.insertMany([
{
"_id":1,
"order":"phones"
}
])
j)
db.order.insertMany([
{
"_id":1,
"ShippingDetails":"Bangalore",
"BillingDetails":"Bangalore"
}
])
- Write a query to find the average order value for all Customers.
Ans:
db.customer.aggregate([
{
$group: {_id:"$by_user",Average : $avg :"$Order Value"
}
])
- Query your database to get top 10 customers whose orders have the highest value and who have been customers since less than 2 months
Ans:
db.orders.find({$and:[{$max:"orders"},{"customers_date"<60}]})
3.Query your database to find the sum of all orders received in this month
Ans:
db.orders.find({$and:[{$sum:"orders"},{$match:{"month":11}}]})
4.Query your database to find all customers count in various cities, order them by names of cities
Ans:
db.customers.distinct("city").count()
5.Query your database to find the product counts per tag used in your ecommerce portal
Ans;
db.products.distinct("tags").count()
6.Query your database to get all the sellers who have base in the same city in which the customers who ordered their products. Order them in the order of highest number of products sold to customers in same city to lowest.
Ans:
db.sellers.find({$and:[{distinct("city")},{$match:{"orders"}}]})