Challenge

Project 2

  1. Create your collections for your ecommerce database in MongoDB and fill it with sample information
  2. Submit all the queries used to create the database

use ecommerce

db.customers.insertMany([
{"_id":1001,"Name":"Ramesh B","Gender":"Male","Age":23,"DOB":'1999-12-12',"add":"yjgfhhfg","City":"Nagpur","state":"Maharashtra",
"country":"India","customer_type":"Normal"},
{"_id":1002,"Name":"Shivani VN","Gender":"Female","Age":22,"DOB":'2000-10-09',"add":"nhgfxfdfd","City":"Mumbai","state":"Maharashtra",
"country":"India","customer_type":"Premium"},
{"_id":1003,"Name":"Ritika H","Gender":"Female","Age":20,"DOB":'2002-01-02',"add":"tteersxhi","City":"Dwarka","state":"Delhi",
"country":"India","customer_type":"Normal"},
{"_id":1004,"Name":"Shravan KM","Gender":"Male","Age":24,"DOB":'1998-12-08',"add":"dttssdsrfrf","City":"Nagpur","state":"Maharashtra",
"country":"India","customer_type":"Normal"}
])

db.products.insertMany([
{"_id":4689,"prod_name":"Salwar suit","price":789,"brand":"Zara","color":"Blue"},
{"_id":7995,"prod_name":"Saree","price":1000,"brand":"Zara","color":"Black"},
{"_id":9865,"prod_name":"Mens wear shoes","price":800,"brand":"Puma","color":"white"},
{"_id":4976,"prod_name":"Accessories-earing","price":70,"brand":"null","color":"golden"}
])

db.cart.insert([
{"_id":8666,"cartprod_name":"Sherwani","price":1200,"prod_id":7646,"Payment":"Cash on delivery"},
{"_id":6478,"cartprod_name":"Ceiling fan","price":750,"prod_id":4563,"Payment":"UPI"},
{"_id":9543,"cartprod_name":"Womens kurti","price":358,"prod_id":9764,"Payment":"Google pay"},
{"_id":8634,"cartprod_name":"Books","price":600,"prod_id":4357,"Payment":"Cash on delivery"}
])

db.admin.insert([
{"_id":123,"name":"shravan kumar","gender":"male","age":30,"add":"Mahal nagpur","city":"nagpur","state":"Maharashtra","country":"India"}
])

db.sellers.insertMany([
{"_id":78650,"name":"ketki","gender":"female","product":"Saree","shop":"ketki sarees","city":"mumbai","price":900},
{"_id":78651,"name":"aman","male":"female","product":"Male suits","shop":"Oneandonly shop","city":"akola","price":1400},
{"_id":78652,"name":"ani","gender":"male","product":"shoes","shop":"shoesshop","city":"ludhiyana","price":850},
{"_id":78653,"name":"fatima","gender":"female","product":"fabrics","shop":"MyFabrics","city":"lucknow","price":350},
{"_id":78654,"name":"yashi","gender":"female","product":"Saree","shop":"sarees store","city":"delhi","price":1000}
])

db.orders.insertOne([
{"_id":900,"name":"Ramesh B","product":"mens wear shoes","prod_id":9865,"price":800,"shipping details":"delivered by":'2022-12-19'}
])

Simple Queries to perform on ecommerce db

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

db.orders.aggregate([{$group:{_id:"$name",num_tutorial:{$avg:"$price"}}}])

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

db.customers.find({order_amt}).sort({"title":1}).limit(10)

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

db.orders.aggregate([{$group:{_id:"$name",num_tutorial:{$sum:"$price"}}}])

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

db.customers.aggregate({$count:"City"})

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.

db.getCollection('customers').aggregate([{$lookup:
{from: 'seller',localField: 'city',as: 'same_city'}
}]);

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.