Project 2
1. Design your ecommerce database in MongoDB with the specifications provided below
a]
test> use ecommerceswebsite
switched to db ecommerceswebsite
ecommerceswebsite> db
ecommerceswebsite
ecommerceswebsite> db.CreateCollection("Customers")
ecommerceswebsite> db.Customers.insert(
... {
... "CustomersID":1,
... "CustomersName":"deepika",
... "CustomersDOB":20-10-2000,
... "CustomersContact":5656565656,
... "CustomersType":"premium"
... }
... )
DeprecationWarning: Collection.insert() is deprecated. Use insertOne, insertMany, or bulkWrite.
{
acknowledged: true,
insertedIds: { '0': ObjectId("6386199c921ddd66edb9237d") }
}
b]
ecommerceswebsite> db.Customers.find({"CustomerType"})
c]
ecommerceswebsite> db.carts.insert({
... _id:"the_useres_session_id",
... status:'active',
... quantity:2,
... total:2000,
... products:[]
... });
{ acknowledged: true, insertedIds: { '0': 'the_useres_session_id' } }
d]
db.Products.insert(
... {
... "ProductName":"Soaps",
... "ProductID":2,
... "ProductSize":10/10/10,
... "ProductColor":"blue",
... tags:['santoor','rexona','xxx'],
... categories:['facewash','dermacara']
... }
... )
e]
db.subcategories.insertMany(
... {
... item:'facewash',
... name:'ponds',
... cost:30,
... qty:50,
... likes:600
... },
... {
... item:'dermecara',
... name:'body cream',
... cost:100,
... qty:50,
... likes:750
... }
... )
f]
db.products.insert(
... {
... _id:2,
... "name":"janu",
... tag:['size','discount']
... }
... )
DeprecationWarning: Collection.insert() is deprecated. Use insertOne, insertMany, or bulkWrite.
{ acknowledged: true, insertedIds: { '0': 2 } }
ecommercewebsite>
g]
db.Orders.insert({
... created_on:new ISOdate("2012-05-17T08:14:15.656Z"),
... shipping:{
... customer:"peter p peterson",
... address:"longroad 1343",
... city:"pererburg",
... region:"",
... state:"PE",
... country:"peteonia",
... delivery_notes:"leave at the gate",
... tracking:{
... company:"UPS",
... tracking_number:"22122*211SD",
... status:'ontruck',
... estimated_delivery:new ISOdate("2012-05-17T08:14:15.656Z")
... },
... },
... payment:{
... method:"Visa"
... transaction_id:"2312213312XXXTD"
...}
...products:{
...{quentity:2,sku:"111445GB3",title:"Simsong",
...mobile phone:unit_cost:1000,currency:"USDA"}
...}
...})
h]
db.seller.insert(
... {
... "SellerName":"pushpa",
... "SellerID":2Aa,
... "SellerContact":5656565656
... }
... )
ecommercewebsite> db.products.insert(
... [
... {_id:11,item:"pencil",qty:50,type:"no.2"},
... {item:"pen",qty:20},
... {item:"earser",qty:25}
... ]
... )
ecommercewebsite> db.Admin.insert(
... {
... "AdminName":"pooja",
... "AdminID":23,
... "AdminEmail":"[email protected]"
... }
... )
ecommercewebsite> db.products.insert(
... [
... {_id:11,item:"pencil",qty:50,type:"no.2"},
... {item:"pen",qty:20},
... {item:"eraser",qty:25}
... ]
... )
j]
db.Orders.insert({
... created_on:new ISOdate("2012-05-17T08:14:15.656Z"),
... shipping:{
... customer:"peter p peterson",
... address:"longroad 1343",
... city:"pererburg",
... region:"",
... state:"PE",
... country:"peteonia",
... delivery_notes:"leave at the gate",
... tracking:{
... company:"UPS",
... tracking_number:"22122*211SD",
... status:'ontruck',
... estimated_delivery:new ISOdate("2012-05-17T08:14:15.656Z")
... })
k]
db.seller.insert(
... {
... "SellerName":"pushpa",
... "SellerID":2,
... "SellerContact":5656565656
... }
... )
1.Create your collections for your ecommerce database in MongoDB and fill it with sample information
db.CreateCollection("SampleDatabase")
ecommercewebsite> db.SampleDatabase.insert(
... {
... CustName:"pavan",
... _id:27,
... DOB:20-20-1999,
... contact:899898989
... }
... )
{ acknowledged: true, insertedIds: { '0': 27 } }
ecommercewebsite> db.Seller.insert(
... {
... Name:"manoj",
... _id:88,
... contact:786756455,
... DOB:23-6-2000
... }
... )
{ acknowledged: true, insertedIds: { '0': 88 } }
ecommercewebsite> db.Admin.insert(
... {
... name:"paul",
... _id:7,
... DOB:28-6-2002,
... contact:45456789
... }
... )
{ acknowledged: true, insertedIds: { '0': 7 } }
ecommercewebsite> db.product.insert(
... {
... name:"tables",
... dimensentions:['height','weidth','colour'],
... cost:500,
... qty:50%
... }
ecommercewebsite> db.cart.insert(
... {
... name:"tables",
... dimensentions:['height','weidth','colour'],
... cost:500,
... qty:50,
... shipping:("vijayawada",18-58,"church road")
... }
... )
{
acknowledged: true,
insertedIds: { '0': ObjectId("63899cd66ce34766fae7aa08") }
}
2.Submit all the queries used to create the database
db.CreateCollection("Customers")
ecommerceswebsite> db.Customers.insert(
... {
... "CustomersID":1,
... "CustomersName":"deepika",
... "CustomersDOB":20-10-2000,
... "CustomersContact":5656565656,
... "CustomersType":"premium"
... }
... )
DeprecationWarning: Collection.insert() is deprecated. Use insertOne, insertMany, or bulkWrite.
{
acknowledged: true,
insertedIds: { '0': ObjectId("6386199c921ddd66edb9237d") }
}
ecommerceswebsite> db.Customers.find({"CustomerType"})
ecommerceswebsite> db.carts.insert({
... _id:"the_useres_session_id",
... status:'active',
... quantity:2,
... total:2000,
... products:[]
... });
{ acknowledged: true, insertedIds: { '0': 'the_useres_session_id' } }
db.Products.insert(
... {
... "ProductName":"Soaps",
... "ProductID":2,
... "ProductSize":10/10/10,
... "ProductColor":"blue",
... tags:['santoor','rexona','xxx'],
... categories:['facewash','dermacara']
... }
... )
db.subcategories.insertMany(
... {
... item:'facewash',
... name:'ponds',
... cost:30,
... qty:50,
... likes:600
... },
... {
... item:'dermecara',
... name:'body cream',
... cost:100,
... qty:50,
... likes:750
... }
... )
db.products.insert(
... {
... _id:2,
... "name":"janu",
... tag:['size','discount']
... }
... )
DeprecationWarning: Collection.insert() is deprecated. Use insertOne, insertMany, or bulkWrite.
{ acknowledged: true, insertedIds: { '0': 2 } }
ecommercewebsite>
db.Orders.insert({
... created_on:new ISOdate("2012-05-17T08:14:15.656Z"),
... shipping:{
... customer:"peter p peterson",
... address:"longroad 1343",
... city:"pererburg",
... region:"",
... state:"PE",
... country:"peteonia",
... delivery_notes:"leave at the gate",
... tracking:{
... company:"UPS",
... tracking_number:"22122*211SD",
... status:'ontruck',
... estimated_delivery:new ISOdate("2012-05-17T08:14:15.656Z")
... },
... },
... payment:{
... method:"Visa"
... transaction_id:"2312213312XXXTD"
...}
...products:{
...{quentity:2,sku:"111445GB3",title:"Simsong",
...mobile phone:unit_cost:1000,currency:"USDA"}
...}
...})
db.seller.insert(
... {
... "SellerName":"pushpa",
... "SellerID":2Aa,
... "SellerContact":5656565656
... }
... )
ecommercewebsite> db.products.insert(
... [
... {_id:11,item:"pencil",qty:50,type:"no.2"},
... {item:"pen",qty:20},
... {item:"earser",qty:25}
... ]
... )
ecommercewebsite> db.Admin.insert(
... {
... "AdminName":"pooja",
... "AdminID":23,
... "AdminEmail":"[email protected]"
... }
... )
Simple Queries to perform on ecommerce db
1]db.customer.aggregate({$avg:"order_amt"})
2]db.customer.find({order_amt}).sort({"title":1}).limit(10)
3]db.order.aggregate({$sum:order_amt})
4]db.customer.aggregate([ {$group : {_id:"$city", count:{$cust_id}} ])
5]
db.getCollection('customer').aggregate([{$lookup:
{from: 'seller',localField: 'city',as: 'same_city'}
}]);