Ecommerce database in MongoDB
1. Design your ecommerce database in MongoDB with the specifications provided Below :
db.collection.createIndex({name:"customer productDetails"})
db.customer productDetails.insertMany([
{_id:1,item:"mobiles",cost:"25000",brand:"1",category:"a", segments:" color:"green",size:"6inch"},
{_id:2,item:"laptops",cost:"45000",brand:"1",category:"b", segments:" color:"silver"},
{_id:3,item:"dresses",cost:"5000",brand:"2",category:"c", segments:" color:"all colors",size:"XL"},
{_id:4,item:"bags",cost:"2000",brand:"3",category:"d",color:" blue"},
]);
db.collection.aggregate({name:'category'})
db.category.insert([
{_id:'678',category:'footwear'},
{_id:'789',category:'cloths'},
{_id:'987',category:'accessories'},
{_id:'423',category:'electronics'},
{_id:'557',category:'jewellery'},
{
$group:
{
"_id":"id",
product:{$name:"$category"}
]);
db.collection.aggregate({name:'sub_category'})
db.sub_category.insertMany([
{_id:'1',items:'electronics'},
{_id:'2',items:'sofas'},
$group:
{
"_id":"id",
product:{$name:"$subcategory"}
]);
db.collection.aggregate({"name":cartDetails})
db.cartDetails.insert([
{_id:'546',product:'add to cart',rename:'delete_Cart',name:'product Added',order:'booked order'}]);
[
{
$group:
{
"_id":"_id",
productname:{$product:'addtocart']};
db.inventory.find({tags:{$product:"c"}});
db.inventory.find({tags:"c"});
db.inventory.find({tags:{$product:"b"}});
db.inventory.find({tags:{$product:"a"}});
db.collection.aggregate({"name":'payment'})
db.payment.insert([
{_id:'987',name:'customer',payment type:'cash on delivery/phonepe/googlepe',order:'booked'}]);
db.collection.createIndex({name:"productDetails"})
db.productDetails.insertMany([
{_id:1,item:"mobiles",cost:"25000",brand:"1",category:"a", segments:" color:"white",size:"100mm"},
{_id:2,item:"laptops",cost:"45000",brand:"1",category:"b", segments:" color:"grey"},
{_id:3,item:"dresses",cost:"5000",brand:"2",category:"c", segments:" color:"all colors",size:"freesize"},
{_id:4,item:"bags",cost:"2000",brand:"3",category:"d",color:"navy blue"},
]);
db.collection.aggregate({name:'category'})
db.category.insert([
{_id:'678',category item 1:'footwear'},
{_id:'789',category item 2:'cloths'},
{_id:'987',category item 3:'accessories'},
{_id:'423',category item 4:'electronics'},
{_id:'557',category item 5:'jewellery'},
{
$group:
{
"_id":"id",
product:{$name:"$category"}
]);
db.collection.aggregate({name:'sub_category'})
db.sub_category.insertMany([
{_id:'1',sub_categoryName:'electronics'},
{_id:'2',sub_categoryName:'sofas'},
$group:
{
"_id":"id",
product:{$name:"$subcategory"}
]);
db.collection.aggregate({"name":cartDetails})
db.cartDetails.insert([
{_id:'555',product:'add_to_cart',rename:'delete_Cart',name:'product_Added',order:'booked_order'}]);
[
{
$group:
{
"_id":"_id",
productname:{$product:'addtocart']};
}
}
db.seller.find({tags:{$product:"c"}});
db.seller.find({tags:"c"});
db.seller.find({tags:{$product:"b"}});
db.seller.find({tags:{$product:"a"}});
db.order.aggregate({"receivedOrder"})
db.receiveOrder.insert({
order date:'25-11-2022',
product:'mobile',
delivery date:'30-11-2022',
confirm order:'confirm/cancel',
receive order:'received'
});
db.shipment.aggregate([
{
db.shipment.insert({
billing name:'Kailash Rajkumar',
billing number:'555',
street:'BTM',
location:'BtM Layout satge 2',
place:'Banglore',
});
$group:{
_id:{shipment:"$shipmentDetails"},
count:{$sum:1}
}
}
{$match:{
count:{"$gt:1}
}
}
]);
db.seller.registered({"sellerDetails"})
db.sellerDetails.insert({
name:"manoj",
mobile number:"7485964598",
address:"chennai city",
pin:"639002",
nation:"india",
});
db:collection.aggregate([
{
db.sellerDetails.insert({
name:"manoj",
mobile number:"7845967845",
address:"chennai city",
pin:"639002",
nation:"india",
});
$group:{
-id:{:"$database"},
count:{$sum:1}
}
}
{$match:{
count:{"$gt":1}
}
}
]);
db.create.database({"submit"})
db.submit.aggregate({
[
submit product:"submitted"]});
1) db.customer.aggregate([{$group:
{
$group:
{
_id:"$item",
avgValue:{$avg:{$multiply:["$price","$quantity"]}},
}
}
])
2) db.greaterthanvalue.find({field1:{$gt:10}});
db.lessthanvalue.find({field1:{$lt:10}});
db.collection.find({field1:{$gt:10,$lt:10});
3) db.collection.find([{
$group:
{
_id:{day:{$dayofYear:"$13"},year:{$year:"$2022"}},
totalAmount:{$sum:{$multiply:["$price","$quantity"]}},
count:{$sum:1}
}
}
]
);
4)db.customers.find([
{
$group:
{$cities:{"$city":"tn"},
$count:{"$cityName":"tamilnadu"},
]})
5)db.seller.find({"cityNames"})
db.cityNames.insert({
city:"tamilnadu",
db.seller.find([
{"cityname":"banglore"},
db.seller.find{"cityname":"tn"},
db.products.find{"name":"Nitish"}
db.highestnumber.find({$product:"3"}),
db.lowestnumber.find({$product:"2"}),
]);