db.orders.insertMany( [
{ “_id” : 1, “item” : “almonds”, “price” : 12, “quantity” : 2 },
{ “_id” : 2, “item” : “pecans”, “price” : 20, “quantity” : 1 },
{ “_id” : 3 }
] )
db.inventory.insertMany( [
{ “_id” : 1, “sku” : “almonds”, “description”: “product 1”, “instock” : 120 },
{ “_id” : 2, “sku” : “bread”, “description”: “product 2”, “instock” : 80 },
{ “_id” : 3, “sku” : “cashews”, “description”: “product 3”, “instock” : 60 },
{ “_id” : 4, “sku” : “pecans”, “description”: “product 4”, “instock” : 70 },
{ “_id” : 5, “sku”: null, “description”: “Incomplete” },
{ “_id” : 6 }
] );
db.sales.insertMany([
{ “_id” : 1, “item” : “abc”, “price” : Decimal128(“10”), “quantity” : Int32(“2”), “date” : ISODate(“2014-03-01T08:00:00Z”) },
{ “_id” : 2, “item” : “jkl”, “price” : Decimal128(“20”), “quantity” : Int32(“1”), “date” : ISODate(“2014-03-01T09:00:00Z”) },
{ “_id” : 3, “item” : “xyz”, “price” : Decimal128(“5”), “quantity” : Int32( “10”), “date” : ISODate(“2014-03-15T09:00:00Z”) },
{ “_id” : 4, “item” : “xyz”, “price” : Decimal128(“5”), “quantity” : Int32(“20”) , “date” : ISODate(“2014-04-04T11:21:39.736Z”) },
{ “_id” : 5, “item” : “abc”, “price” : Decimal128(“10”), “quantity” : Int32(“10”) , “date” : ISODate(“2014-04-04T21:23:13.331Z”) },
{ “_id” : 6, “item” : “def”, “price” : Decimal128(“7.5”), “quantity”: Int32(“5” ) , “date” : ISODate(“2015-06-04T05:08:13Z”) },
{ “_id” : 7, “item” : “def”, “price” : Decimal128(“7.5”), “quantity”: Int32(“10”) , “date” : ISODate(“2015-09-10T08:43:00Z”) },
{ “_id” : 8, “item” : “abc”, “price” : Decimal128(“10”), “quantity” : Int32(“5” ) , “date” : ISODate(“2016-02-06T20:20:13Z”) },
])
db.orders.aggregate( [
{
$lookup:
{
from: “inventory”,
localField: “item”,
foreignField: “sku”,
as: “inventory_docs”
}
}
] )
db.Products.aggregate( [
{
$lookup:
{
from: “Reviews”,
localField: “ReviewIds”,
foreignField: “_id”,
as: “enrollee_info”
}
}
] )
db.Products.aggregate(
[
{
$lookup: {
from: “Products”,
localField: “ReviewIds”,
foreignField: “_id”,
as: “movie_details”
}
}]
);