Project 2
Ans 1:-(a)personal infromation of customer:-
db.customer.insertMany([{
customer_id:1,"customer_name":"ram",contact:9167854,"city":"delhi","address":"houseno","email":"[email protected]",arrivaldate:1,member:["normal","premium"],order_value:5000,view_products":"viewall","addtocart":"addproduct",product_id:111},
customer_id:2,"customer_name":"shyam",contact:91897984,"city":"bengaluru","email":"[email protected]",arrivaldate:3,member:["normal","premium"],"view_products":"viewall","addtocart":"addproduct",product_id:121}
]);
(b)memeber:-
db.customer.insertMany([{
customer_id:1,"customer_name":"ram",contact:9167854,"city":"delhi","address":"houseno","email":"[email protected]",arrivaldate:1,member:["normal","premium"],order_value:5000,view_products":"viewall","addtocart":"addproduct",product_id:111},
customer_id:2,"customer_name":"shyam",contact:91897984,"city":"bengaluru","email":"[email protected]",arrivaldate:3,member:["normal","premium"],"view_products":"viewall","addtocart":"addproduct",product_id:121}
]);
(c)viewproducts:-
db.customer.find{"view_products":"viewall","addtocart":"addproductocart"};
(d)multiple categories ans brands:-
db.products.insertMany([{product_id:111,"product_name":"zaratop",price:2500,"product_code":"ZAZA",category:["clothes","shoes","fashion"],subcategory:["jeans","sneakers","makeup"],"brand":"Zara","segments":"seg","tags":"clothestag"},
{product_id:121,"product_name":"shoesnike",price:25000,"product_code":"NIKE",category:["books","electrnicgadgets"],subcategory:["javabook","laptop"],"brand":"nike","segments":"seg1""tags":"shoestag"}]);
(e)subcategories:-
db.products.insertMany([{product_id:111,"product_name":"zaratop",price:2500,"product_code":"ZAZA",category:["clothes","shoes","fashion"],subcategory:["jeans","sneakers","makeup"],"brand":"Zara","segments":"seg","tags":"clothestag"},
{product_id:121,"product_name":"shoesnike",price:25000,"product_code":"NIKE",category:["books","electrnicgadgets"],subcategory:["javabook","laptop"],"brand":"nike","segments":"seg1""tags":"shoestag"}]);
(f)multiple tags:-
db.products.insertMany([{product_id:111,"product_name":"zaratop",price:2500,"product_code":"ZAZA",category:["clothes","shoes","fashion"],subcategory:["jeans","sneakers","makeup"],"brand":"Zara","segments":"seg","tags":"clothestag"},
{product_id:121,"product_name":"shoesnike",price:25000,"product_code":"NIKE",category:["books","electrnicgadgets"],subcategory:["javabook","laptop"],"brand":"nike","segments":"seg1""tags":"shoestag"}]);
(g)checkout and make payment:-
db.cart.insertMany([{cart_id:11,"product_name":"zaratop",product_id:111,"order_status":"orderplaced",checkout:["yes","no"]}]);
(h)admin and seller:-
db.admin.insertMany([{admin_id:201,"admin_name":"shyam",product_id:121,"addproducts":"addproduct"}])
db.addproducts.insertMany([{seller_id:123,admin_id:201,product_id:121,"product_name":"zaratop"}]);
(i)seller recieve orders:-
db.seller.insertMany([{seller_id:123,"seller_name":"george","seller_shop":"habitt",order_id:901,contact:901234,"city":"mumbai","order_status":"placed"},
{seller_id:124,"seller_name":"mathew","seller_shop":"collectionofclothes",order_id:902,contact:908894,"city":"surat","order_stauts":"pending"}
]);
(j)shipping and billing information:-
db.shipping.insertMany([{shipping_id:123456,"shipping_name":"NSDN",shipping_date:2020-12-12,order_id:901,order_date:2020-12-08,"order_name":"nameoforder",billinginformation:["googlepay","COD","debitcard","generated"],"order_status":"placed","ordertracking":"trackorder"}]);
(k)seller all personal information:-
db.seller.insertMany([{seller_id:123,"seller_name":"george","seller_shop":"habitt",order_id:901,contact:901234,"city":"mumbai","order_status":"placed"},
{seller_id:124,"seller_name":"mathew","seller_shop":"collectionofclothes",order_id:902,contact:908894,"city":"surat","order_stauts":"pending"}
]);
Ans 1:-create collection and create databse:-
use ecommerce;
db.customer.insertMany([{customer_id:1,"customer_name":"john","city":"dlehi"}]);
db.cart.insertMany([{cart_id:11,"order_staus":"orderplaced"}]);
db.products.insertMany([{product_id:111,"product_name":"zaratop",price:2500}]);
db.seller.insertMany([{seller_id:124,"seller_name":"george","seller_shop":"habitt","city":"mumbai"}]);
db.admin.insertMany([{admin_id:201,"admin_name":"seller"}]);
Ans 2:-(1)-
db.aggregateExample.aggregate([{$group : {_id : "customer_id", average : {$avg : "$order_value"}}}]);
(2)-
db.customer.find({"arrivaldate":{$lt:2}}).sort({"order_value":-1}).limit(10);
(3)-
db.order.aggregate([{$match:{order_date:{$gte:"2020-12-08",$lte:"2020-12-15"}}},{$group:{_id:"order_id" ,numberoforders:{$sum:"$order_id"}}}]);
(4)-
db.movie.aggregate([{$group : {_id : "$city", countcity : {"$sum" : 1}}}]);
(5)-
db.seller.aggregate([{
$lookup:
{
from: 'products',
localField: 'customer_id',
foreignField: 'city',
as: 'orderdetails'
}
},{$group:{_id:"product_id",sumofcity:{$sum:"$product_id"}}}.sort({"city":-1})
]);