Project 2
use ecom
db.customers.insertOne( {
_id: "arnold_jones",
fname: "Arnold",
lname: "Jones",
password: "122333",
emailVerified: false,
address: {
country: "United States",
street1: "99 Main Street",
street2: "Apt #3",
city: "Boston",
state: "MA",
zip: "74586"
}
} )
PRODUCT
db.products.insert({
sku: "111445GB3",
title: "java 2 mobile",
description: "The greatest Onedroid phone on the market .....",
manufacture_details: {
model_number: "A123X",
},
shipping_details: {
weight: 350,
width: 10,
height: 10,
depth: 1
},
quantity: 99,
pricing: {
price: 1000
}
})
sku: "123445GB3",
title: "java mobile",
description: "The greatest camera phone on the market .....",
manufacture_details: {
model_number: "A114X",
},
shipping_details: {
weight: 450,
width: 15,
height: 10,
depth: 1
},
quantity: 99,
pricing: {
price: 1500
}
})
SELLER
db.seller.insertOne( {
_id: "jack_miller",
fname: "Jack",
lname: "Miller",
address: {
street: "Longroad 1343",
city: "Peterburg",
state: "PE",
country: "Peteonia",
zip: "68586"
}
} )
CATEGORY
db.products.update({sku: "111445GB3"}, {$set: { categories: ['mobile/15G', 'mobile/fm'] }});
db.products.ensureIndex({categories:1 })
{
title: "Mobiles containing a FM radio",
parent: "mobile",
path: "mobile/fm"
}
db.categories.find({parent: /^mobile/}, {_id: 0, path: 1})
CART
db.carts.insert({
_id: "arnold_jones",
status:'active',
quantity: 2,
total: 2000,
products: []});
db.carts.update({
_id: "the_users_session_id", status:'active'
}, {
$set: { modified_on: ISODate() },
$push: {
products: {
sku: "111445GB3", quantity: 1, title: "java 2 mobile ", price:1000
}
}
});
ORDERS
db.orders.insert({
created_on: new ISODate("2012-05-17T08:14:15.656Z"),
shipping: {
customer: "Arnold Jones",
country: "United States",
street1: "99 Main Street",
street2: "Apt #3",
city: "Boston",
state: "MA",
zip: "74586"
delivery_notes: "Leave at the gate",
tracking: {
company: "ups",
tracking_number: "22122X211SD",
status: "ontruck",
estimated_delivery: new ISODate("2012-05-17T08:14:15.656Z")
},
},
payment: {
method: "visa",
transaction_id: "2312213312XXXTD"
}
products: {
{quantity: 2, sku:"111445GB3", title: "java 2 mobile ", unit_cost:1000, currency:"USDA"}
}
})
1) db.ecom.aggregate([{"customer":{$regex:{"order"}}}]);
2) db.ecom.aggregate([{"customer":{$regex:{"orders"},{"max":1}}}]);
3) db.ecom.aggregate([{"customer":{$sum:{"orders"}}}]);
4) db.zipcodes.distinct("city").length;
5) db.seller.distinct("city").length;
db.seller.find({}).sort("orders":-1);