Project 2
db.inventory.insertOne( { item: "journal",
price: 9.99,
qty: 25,
size: { h: 14, l: 21, w: 1 },
features: "Beautiful, handmade journal.", categories: ["writing", "bestseller"], image: "items/journal.jpg"
} )
db.inventory.updateOne(
{ _id: ObjectId("600e814359ba901629a14e13") },
{
$unset: {image: 1, size: 1, qty: 1, price: 1},
$set : {
item: "journal",
features: ["Inner pocket", "Durable cover"], skus: [ {
sku: "154A",
price: {
base: NumberDecimal(9.99), currency: "USD"
},
quantity: 20, options: {
size: { h: 14, l: 21, w: 1 },
features: ["72 sheets of premium lined paper"], colors: ["brown", "red"],
ruling: "wide",
image: "images/journal1.jpg"
}
}, {
sku: "154B",
price: {
base: NumberDecimal(14.99), currency: "USD",
discount: NumberDecimal(4.00)
},
quantity: 15, options: {
size: { h: 18, l: 22, w: 2 },
features: ["140 sheets of premium paper"], colors: ["brown"],
ruling: "unlined",
image: "images/journals.jpg"
}
} ]
}
}
)
db.customers.createIndex(
{ email: 1 },
{ unique: true }
)
db.customers.createIndex(
{ email: 1 },
{ unique: true }
)
db.runCommand( { collMod: "customers",
validator: { $jsonSchema: { bsonType: "object",
required: [ "hashedAndSaltedPassword", "address" ], properties: {
_id: {
bsonType: "string", pattern: '.+@.+..+',
description: "must match the email pattern"
},
hashedAndSaltedPassword: { bsonType: "string", minLength: 10,
description: "must be a string ten characters long, and is required"
},
address: {
bsonType: "object", required: [ "street1", "zip" ], properties: {
zip: {
pattern: "^[0-9]{5}(?:-[0-9]{4})?$",
description: "must match pattern and is required"
},
street1: {
bsonType: "string",
description: "must be a string and is required" }, street2: {
bsonType: "string",
description: "must be a string" }
},
description: "must be an object, and is required"
}
}
} },
} )
db.payments.insertOne( {
customerId: "journalfanatic@e/mail.com",
status: "verified", gateway: "stripe", type: "credit",
amount: NumberDecimal(1.00), card: {
brand: "Visa",
pan: "4242424242424242",
expirationMonth: 1,
expirationYear: 2090,
cvv: 123
}
} )
db.payments.remove( { } ) db.payments.insertOne( {
customerId: "journalfanatic@e/mail.com", status: "verified",
gateway: "stripe", type: "credit",
amount: NumberDecimal(1.00), card: {
brand: "Visa", panLastFour: "4242",
expirationMonth: 1,
expirationYear: 2090, cvvVerified: true
}
} )
db.payments.insertOne( {
customerId: "journalfanatic@e/mail.com", status: "awaitingVerification",
gateway: "stripe", type: "token",
token: "card_1IDHBZFdjJUqVVV2gPlbz8BC"
} )
db.orders.insertOne( {
customerId: "journalfanatic@e/mail.com", paymentId: "600e6f37aa2232f59e273082",
paymentStatus: "paid",
status: "shippedAwaitingDelivery", currency: "USD",
totalCost: NumberDecimal(39.85) items: [
{ sku: "154B",
quantity: "2",
price: NumberDecimal(14.99), discount: NumberDecimal(1.00), preTaxTotal: NumberDecimal(27.98), tax: NumberDecimal(1.00),
total: NumberDecimal(28.98),
}, { sku: "154A",
quantity: "1",
price: NumberDecimal(9.99), preTaxTotal: NumberDecimal(9.99), tax: NumberDecimal(.87),
total: NumberDecimal(10.86)
}
],
shipping: {
address:{
street1: "50 Work Street", street2: "Floor 16",
city: "Chicago", state: "IL", country: "USA", zip: "60601"
},
origin: {
street1: "1 Penn Ave", street2: "",
city: "New York", state: "NY", country: "USA", zipCode: "46281"
},
carrier: "USPS",
tracking: "123412341234"
}
} )