Challenge

Project 2

use Ecommerce;



/*Every Customer would register on the ecommerce website with all their personal information
Each Customer has a type of being normal or premium member*/

db.customer.insertOne([{user_id:"1001",first_name:"Emma", last_name:"Watson",
contact:"xxyy", dob:"...", username:"emmawatson" ,password:"xxyyxx", address:[{street:"..........."}],
customer_type:["Premium"],city:'A'}]);
db.customer.insertOne([{user_id:"1002",first_name:"Emma", last_name:"Robers",
contact:"xxyy", dob:"...", username:"emmaroberts" ,password:"xxyyxx", address:[{street:"..........."}],
customer_type:["Normal"],city:'B'}]);
db.customer.insertOne([{user_id:"1003",first_name:"Emma", last_name:"stone",
contact:"xxyy", dob:"...", username:"emmastone" ,password:"xxyyxx", address:[{street:"..........."}],
customer_type:["Premium"],city:'C'}]);
db.customer.insertOne([{user_id:"1004",first_name:"Emma", last_name:"mackey",
contact:"xxyy", dob:"...", username:"emmamackey" ,password:"xxyyxx", address:[{street:"..........."}],
customer_type:["Normal"],city:'D'}]);
db.customer.insertOne([{user_id:"1005",first_name:"Keanu", last_name:"Reevees",
contact:"xxyy", dob:"...", username:"Keanureevees" ,password:"xxyyxx", address:[{street:"..........."}],
customer_type:["Premium"],city:'E'}]);
db.customer.insertOne([{user_id:"1006",first_name:"John", last_name:"Wick",
contact:"xxyy", dob:"...", username:"John Wick" ,password:"xxyyxx", address:[{street:"..........."}],
customer_type:["Normal"],city:'F'}]);
db.customer.insertOne([{user_id:"1007",first_name:"Margot", last_name:"Robie",
contact:"xxyy", dob:"...", username:"Margot" ,password:"Robie", address:[{street:"..........."}],
customer_type:["Normal"],city:'G'}]);
db.customer.insertOne([{user_id:"1008",first_name:"Ellen", last_name:"Page",
contact:"xxyy", dob:"...", username:"EllenPage" ,password:"xxyyxx", address:[{street:"..........."}],
customer_type:["Premium"],city:'H'}]);
db.customer.insertOne([{user_id:"1009",first_name:"Jason", last_name:"Santham",
contact:"xxyy", dob:"...", username:"JasonSantham" ,password:"xxyyxx", address:[{street:"..........."}],
customer_type:["Premium"],city:'I'}]);
db.customer.insertOne([{user_id:"1010",first_name:"Marquert", last_name:"QUallery",
contact:"xxyy", dob:"...", username:"Marquert Qualley" ,password:"xxyyxx", address:[{street:"..........."}],
customer_type:["Normal"],city:'N'}]);




/*c)*/
/*1)*/
db.products.insertOne({product_id:2000,
price:10000,customer_id:1001,category_id:10,
description:"....",
name:"Electronics",
caterories:['mobile','television','laptop','console','watch']});

db.cart.insertOne([{cart_id:"1",product_id:"2000",customer_id:"1001",count:"1"}]);

db.products.insertOne({product_id:3000,
price:20000,customer_id:1002,category_id:10,
description:"....",
name:"Jewellery",
caterories:['rings', 'bracelets', 'chains', 'necklaces', 'nose rings']});

db.cart.find();


/*2)*/
db.cart.insertOne({product:[{product_id:2000,
price:10000,customer_id:1001,category_id:10,
description:"....",
name:"Electronics",
caterories:['mobile','television','laptop','console','watch']}]});


db.cart.find();


/*d,e,f*/
/*
Products can belong to multiple categories, brands and segments.
Each category can have subcategories as well.
Each products can also have multiple tags associated with it.\
*/

db.products.insertOne({product_id:3000,
price:20000,customer_id:1002,category_id:10,
description:"....",
name:"Jewellery",
caterories:['rings', 'bracelets', 'chains', 'necklaces', 'nose rings']});


/*
From the cart, the customer should be able to check out and make payment and his/her order would be booked which the customer can track
From the cart, the customer should be able to check out and make payment and his/her order would be booked which the customer can track
The admin of the ecommerce and the seller both can add products under multiple categories, segments and tags
The seller would receive the orders and should be able to fulfil them.
The order shipping details and the billing information are very important things to be stored in the database as well.
Every Seller would register on the ecommerce website with all their personal information.
*/

db.orders.insert({
order_id:9,
cart_id:1,
created_on:"..",
customer_id:1002,
shipping: {
customer: "Emma Watson",
address: "...",
city: "....",
region: "",
state: "PE",
country: "France",
delivery_notes: "Leave at the gate",

tracking: {
company: "ups",
tracking_number: "22122X211SD",
status: "ontruck",
estimated_delivery: '.......'
},
payment: {
method: "visa",
transaction_id: "2312213312XXXTD"
},
seller_id:"10"
,
products: {
product_id:3000}
}});


db.orders.insert({
order_id:4,
cart_id:2,
created_on:"..",
customer_id:1004,
shipping: {
customer: "Emma Makey",
address: "...",
city: "....",
region: "",
state: "PE",
country: "England",
delivery_notes: "Leave at the gate",

tracking: {
company: "ups",
tracking_number: "22122X211SD",
status: "ontruck",
estimated_delivery: '.......'
},
payment: {
method: "visa",
transaction_id: "2312213312XXXTD"
},
seller_id:"20"
,
products: {
product_id:2000}
}});








db.orders.insert({
order_id:2,
cart_id:2,
created_on:"..",
customer_id:1005,
shipping: {
customer: "Keanu Reeves",
address: "...",
city: "....",
region: "",
state: "PE",
country: "US",
delivery_notes: "Leave at the gate",

tracking: {
company: "ups",
tracking_number: "22122X211SD",
status: "ontruck",
estimated_delivery: '.......'
},
payment: {
method: "visa",
transaction_id: "2312213312XXXTD"
},
seller_id:"30"
,
products: {
product_id:2000}
}});





db.getCollection('orders').aggregate([{ $lookup: { from:'cart', localField:'cart_id', foreignField:'cart_id', as :'orderdetails' }}]);


db.seller.insert({seller_id:"10",first_name:"Keanu", last_name:"Reeves",
contact:"xxyy", dob:"...", username:"Keanu Reeves" ,password:"xxyyxx", address:[{street:"..........."}],city:"A"});

db.seller.insert(
{seller_id:"20",first_name:"John", last_name:"Wick",
contact:"xxyy", dob:"...", username:"JohnWick" ,password:"xxyyxx", address:[{street:"..........."}],city:"O"});



db.getCollection('orders').aggregate([{ $lookup: { from:'customer', localField:'user_id', foreignField:'customer_id', as :'orderdetails'}}]);




/*1*/
db.products.aggregate([{$group : { "_id":"$product_id", num : {$avg : "$price"}}}]);



db.orders.updateOne(
{cart_id:1},
{
$set :{created_on: new Date()}
});


/*3*/


db.orders.aggregate({ $count: "order_id"});


/*4*/

db.customer.aggregate( [
{ $group: { _id: "$city", myCount: { $sum: 1 } } },
{ $project: { _id: 0 } }
] );




/*5*/
db.getCollection('seller').aggregate([{ $lookup: { from:'customer', localField:'city', foreignField:'city', as :'Sellerdetails'}}]);




























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.