Challenge

Project 2

1.

db.customer.insertMany([

(cust_id:1, cust_name: "Anjali", email: "[email protected]", city: "delhi", order_value: "2000", order_date: "2023-01-13"}, (cust_id:2, cust_name: "Swathi", email: "[email protected]", city: "bangalore",order_value: "3000",order_date: "2822-01-13"), (cust_id:3,cust_name: "Riya", email: "[email protected]",city: "Mumbai",order_value:"1000",order_date: "2023-02-13"), (cust_id:4, cust_name: "Abhishek", email: "[email protected]",city: "delhi",order_value: "2000", order_date: "2023-01-13"} ])

db.product.insertMany ([

{pro_id:1,pro_name: "watch", cost:5000, qty:5},

{pro_id:2, pro_name: "TV", cost: 30000, qty:4},

{pro_id:3, pro_name: "Mobile", cost: 60000, qty:9},

{pro_id:4,pro_name: "Smart watch", cost:5000, qty:5}

])

db.seller.insertMany([

{seller_id:1, seller_name: "Rahul", city: "bangalore", products_sold:4},

{seller_id:2, seller_name: "Aswin", city: "chennai",products_sold:},

{seller_id:3, seller_name: "Rahul", city: "delhi", products_sold:4}

])

db.seller.insertMany([

{seller_id:1, seller_name: "Rahul", city: "bangalore", products_sold:4}, {seller_id:2, seller_name: "Aswin", city: "chennai", products_sold:8},

{seller_id:3, seller_name: "Riya", city: "delhi", products_sold:9}

])

db.customer.aggregate([

{$group: {_id: "cust_id", average_orders: {$avg: "order_value"}}}

])

2.

db.customer.aggregate([

{$match: {order_date: {$1t: "2023-01-01"}}},

{$sort: {order_value: -1}}

])

3.

db.order.aggregate([

{$match: {order_date: {$gte: "2022-01-01", $1te: "2022-01-30"}}},

{$group: {_id: "customer_id", orders: {$sum:1}}}

])

4.

db.customers.aggregate([
// Group by city and count customers
{ $group:
{
_id: "$city",
customer_count: { $sum: 1 }
}
}
])

5.

db.sellers.aggregate([
{ $lookup:
{
from: "orders",
localField: "_id",
foreignField: "seller_id",
as: "orders"
}
},
{ $unwind: "$orders" },

{ $lookup:
{
from: "customers",
localField: "orders.customer_id",
foreignField: "_id",
as: "customer"
}
},

{ $unwind: "$customer" },

{ $match: { "city": "$customer.city" } },

{ $group:
{
_id: "$_id",
num_products_sold: { $sum: 1 }
}
},

{ $sort: { "num_products_sold": -1 } }
])

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.