Challenge

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
... }
... )
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}
... ]
... )
k]
db.seller.insert(
... {
... "SellerName":"pushpa",
... "SellerID":2,
... "SellerContact":5656565656
... }
... )

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'}
}]);

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.