Uploaded by numair69xd

1973 Fahad Iqbal

advertisement
CREATE USER:
use online_shopping_cart
CREATE COLLECTION:
db.createCollection('Company')
db.createCollection('Supplier')
db.createCollection('Inventory')
db.createCollection('Review')
db.createCollection('Cart_Product')
db.createCollection('Cart')
db.createCollection('Order')
db.createCollection('Customer')
db.createCollection('Product')
db.createCollection('Sub_Category')
db.createCollection('Payment')
db.createCollection('Coupon')
db.createCollection('Category')
db.createCollection('Invoice')
INSERT:
db.Company.insertMany([{company_id:1,company_name:"tech1",address:"house 1 G-8 Islamabad",phone_number:12345678},
{company_id:2,company_name:"tech2",address:"house 2 G-9 Islamabad",phone_number:12345625},
{company_id:3,company_name:"tech3",address:"house 3 G-10 Islamabad",phone_number:1235256},
{company_id:4,company_name:"tech4",address:"house 4 G-8 Islamabad",phone_number:12513564},
{company_id:5,company_name:"tech5",address:"house 5 G-11 Islamabad",phone_number:12513426}])
///////////
db.Supplier.insertMany([{supplier_name:"Ali",contact_number:12345677,country_name:"Pakistan",email:"ali1@gmail.com",company_id:1,inventory_id:1},
{supplier_name:"Waqar",contact_number:12345858,country_name:"Pakistan",email:"waqar21@gmail.com",company_id:2,inventory_id:2},
{supplier_name:"Zeeshan",contact_number:12345999,country_name:"Pakistan",email:"zeeshan11@gmail.com",company_id:3,inventory_id:3},
{supplier_name:"Zubair",contact_number:12345678,country_name:"Pakistan",email:"zubair42@gmail.com",company_id:4,inventory_id:4},
{supplier_name:"Ahsan",contact_number:12345679,country_name:"Pakistan",email:"ahsan20@gmail.com",company_id:5,inventory_id:5}])
////////
db.Invetory.insertMany([{inventory_id:1,max_quantity:20},
{inventory_id:2,max_quantity:30},
{inventory_id:3,max_quantity:40},
{inventory_id:4,max_quantity:50},
{inventory_id:5,max_quantity:70}])
//////////
db.Review.insertMany([{review_id:1,review_score:8,description:"good",customer_id:1,product_key:1},
{review_id:1,review_score:9,description:"good",customer_id:3,product_key:2},
{review_id:1,review_score:10,description:"good",customer_id:2,product_key:3},
{review_id:1,review_score:7,description:"good",customer_id:5,product_key:4},
{review_id:1,review_score:9,description:"good",customer_id:4,product_key:5}])
//////////////////////
db.Cart_Product.insertMany([{cart_product_id:1,quantity:20,cart_id:1,product_id:2},
{cart_product_id:2,quantity:10,cart_id:3,product_id:3},
{cart_product_id:3,quantity:40,cart_id:2,product_id:1},
{cart_product_id:4,quantity:50,cart_id:5,product_id:4},
{cart_product_id:5,quantity:70,cart_id:4,product_id:5}])
/////////////////////////
db.Cart.insertMany([{cart_id:1,customer_id:1},
{cart_id:2,customer_id:2},
{cart_id:3,customer_id:3},
{cart_id:4,customer_id:4},
{cart_id:5,customer_id:5}])
////////////////////
db.Order.insertMany([{order_id:1,"status":"done","shipping_method":"air","date&time":"6/08/2020 2:18AM"},
{order_id:2,"status":"in process","shipping_method":"air","date&time":"8/08/2020 10:18AM"},
{order_id:3,"status":"done","shipping_method":"air","date&time":"5/05/2020 4:18PM"},
{order_id:4,"status":"in process","shipping_method":"air","date&time":"6/09/2020 2:18PM"},
{order_id:5,"status":"in process","shipping_method":"air","date&time":"10/09/2020 9:18AM"}])
///////////////
db.Customer.insertMany([{customer_id:1,customer_name:"Ahsan",shipping_address:"house 5 G-11 Islamabad",phone_number:12345678},
{customer_id:1,customer_name:"Waqar",shipping_address:"house 1 G-12 Islamabad",phone_number:12345699},
{customer_id:1,customer_name:"Zeeshan",shipping_address:"house 3 G-8 Islamabad",phone_number:12345665},
{customer_id:1,customer_name:"Zubair",shipping_address:"house 4 G-9 Islamabad",phone_number:12345655},
{customer_id:1,customer_name:"Ali",shipping_address:"house 2 G-10 Islamabad",phone_number:12345612}])
/////////////////////
db.Payment.insertMany([{payment_id:1,payment_method:"cash",amount:1000},
{payment_id:2,payment_method:"credit",amount:10000},
{payment_id:3,payment_method:"cash",amount:2000},
{payment_id:4,payment_method:"cash",amount:3000},
{payment_id:5,payment_method:"credit",amount:1500}])
///////////////////
db.Invoice.insertMany([{invoice_id:1,invoice_status:"payed",payment_id:1,order_id:1},
{invoice_id:2,invoice_status:"not payed",payment_id:2,order_id:2},
{invoice_id:3,invoice_status:"payed",payment_id:3,order_id:3},
{invoice_id:4,invoice_status:"payed",payment_id:4,order_id:4},
{invoice_id:5,invoice_status:"not payed",payment_id:5,order_id:5}])
///////////////
db.Product.insertMany([{product_id:1,product_name:"abc",available_quantity:5,type:3,price:2000,description:"good",subcategory_id:1,ineventory_id:1,coupon_id:1},
{product_id:2,product_name:"bcd",available_quantity:10,type:2,price:200,description:"good",subcategory_id:2,ineventory_id:1,coupon_id:2},
{product_id:3,product_name:"efg",available_quantity:3,type:2,price:1000,description:"good",subcategory_id:3,ineventory_id:1,coupon_id:3},
{product_id:4,product_name:"hij",available_quantity:4,type:1,price:12000,description:"good",subcategory_id:4,ineventory_id:1,coupon_id:4},
{product_id:5,product_name:"wrs",available_quantity:10,type:5,price:22000,description:"good",subcategory_id:5,ineventory_id:1,coupon_id:5}])
//////////
db.Coupon.insertMany([{coupon_id:1,discount:"25%",expiry_date:"6/08/2020",coupon_number:1234,quantity:3},
{coupon_id:2,discount:"25%",expiry_date:"22/09/2020",coupon_number:1235,quantity:3},
{coupon_id:3,discount:"50%",expiry_date:"6/07/2020",coupon_number:1236,quantity:3},
{coupon_id:4,discount:"55%",expiry_date:"6/02/2021",coupon_number:1237,quantity:3},
{coupon_id:5,discount:"75%",expiry_date:"3/09/2020",coupon_number:1238,quantity:3}])
/////////////////////////
db.Sub_Category.insertMany([{subcategory_id:1,"subcategory_name":"eee",category_id:1},
{subcategory_id:2,"subcategory_name":"asd",category_id:2},
{subcategory_id:3,"subcategory_name":"bbb",category_id:3},
{subcategory_id:4,"subcategory_name":"ccc",category_id:4},
{subcategory_id:5,"subcategory_name":"ddd",category_id:5}])
////////////////////////////////////
db.Category.insertMany([{category_id:1,category_name:"abc"},
{category_id:2,category_name:"bcd"},
{category_id:3,category_name:"efg"},
{category_id:4,category_name:"hij"},
{category_id:5,category_name:"lmno"}])
///////////////////////
WHERE CLAUSE:
db.Product.find({"price":{$lt:1000}}).pretty() //lesss than
db.Product.find({"price":{$lte:1000}}).pretty() //less than equal
db.Product.find({"price":{$gt:1000}}).pretty() //greater than
db.Product.find({"price":{$gte:1000}}).pretty() //greater than equals
db.Product.find({"price":{$ne:1000}}).pretty() //not equal
db.Product.find({"price":1000}).pretty() //equal
db.Product.find( { price: { $in: [ 1000, 1500] } } ).pretty() //in
db.Product.find({"price":{ $gte:1000, $lt:3000 } //between
}).pretty();
///////////////////
EMBEDDED DOCUMENTS
db.Company.insert({company_id:1,company_name:"tech1",
address:[{house:1, "sector":"G-8", "city":"Islamabad"},
{house:15, "sector":"G-9", "city":"Islamabad"}],
phone_number:12345678})
////////////////////////////
GROUP BY:
db.Coupon.group(
{
key: { "expiry_date": 1, "gross.basic": 1 },
cond: { "date_of_join": { $gt: "01/01/2009" } },
reduce: function ( curr, result ) { },
initial: { }
}
);
db.Product.aggregate([
{ "$group":
{
_id: {
"product_name": "$product_name",
"address": "$address"
}
}
db.Order.aggregate([{$group: {order_id: {}])
db.Product.aggregate( [ { $group : { product_id : "$product_name" } } ] )
db.Order.aggregate( [
{
$group: {
order_id: null,
count: { $sum: 1 }
}
}
] )
db.Payment.aggregate([{$group: {payment_id: null, max: {$max :"$price" }}}])
//////////////////////////////
UPDATE AND DELETE:
db.Category.update({'category_id':1},{$set:{category_name:'bca'}})
db.Category.remove({category_id: 1, category_name: "bca"})
/////////////////////
DROP:
db.Coupon.drop()
/////////////////
TRUNCATE:
db.Company.remove({})
db.Cart_Product.remove({})
db.Cart.remove({})
db.Order.remove({})
db.Supplier.remove({})
db.Customer.remove({})
db.Payment.remove({})
db.Invoice.remove({})
db.Inventory.remove({})
db.Product.remove({})
db.Coupon.remove({})
db.Review.remove({})
db.Sub_Category.remove({})
db.Category.remove({})
Download