Challenge

Project 2

1.)Write a query to find the average order value for all Customers.

Ecommerce>db.orders.aggregate([
{
$group: {
_id: "$customer_id",
avg_order_value: { $avg: "$order_qty" }
}
}
])

2.Query your database to get top 10 customers whose orders have the highest value and who have been customers since less than 2 months


Ecommerce>db.Customer.find([

{"customer_Arrival":{"$lt":"2 months"}}).sort({order_value:-1}).limit(10)

])

3.Query your database to find the sum of all orders received in this month


db.orders.aggregate([
{
$match:{order_date:{$gte:"2022-11-01",$lte:"2022-11-30"}}},
{$group:{_id:"$customer_id",order_qty:{$sum:"$order_qty"}}}

])

4.Query your database to find customers count in various cities, group them by names of cities


Ecommerce> db.customer.aggregate([
 {
$group: {
_id: "$customer_city",
count: { $sum: 1 }
}
}
])

5.)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.


Ecommerce>db.getCollection('seller').aggregate([{
$lookup:
{
from:'customer',
localField:'seller_city',
foreignField:'customer_city',
as:'customerdetails'
}
},
{
"$sort":{
"product_sold":-1
}},
{ $match : { "customerdetails" : { $ne : []}}},
]);
 

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.