// Join in mongoDB
// Customer table
db.customer.insertMany(
[
{ "name": "Abhishek", "age": 50, "address": "f/403 anurag", productId: 1 },
{ "name": "raj", "age": 30, "address": "302 Neelmani", productId: 2 },
{ "name": "simran", "age": 70, "address": "rajkot", productId: 3 },
{ "name": "Dhruval", "age": 60, "address": "chennai", productId: 4 }
]
)
// Product table
db.product.insertMany(
[
{ "product_name": "Abhishek", prod_id: 2, "price": 300 },
{ "product_name": "raj", prod_id: 3, "price": 500 },
{ "product_name": "simran", prod_id: 1, "price": 400 },
{ "product_name": "Dhruval", prod_id: 4, "price": 1000 }
]
)
// Join using lookUp
db.customer.aggregate([
{
$lookup:
{
from: "product",
localField: "productId",
foreignField: "prod_id",
as: "productReference"
}
}
])
let videos= await Beg.aggregate([
{
$project: {
_id: 1,
},
},
{
$lookup: {
from: "videos",
localField: "_id",
foreignField: "begId",
as: "videos",
},
},
]);