Complete the code to embed an address inside a user document in MongoDB.
db.users.insertOne({ name: "Alice", address: [1] })Embedding an address as a sub-document uses an object with fields like street and city.
Complete the code to perform a $lookup join between orders and customers collections.
db.orders.aggregate([{ $lookup: { from: "[1]", localField: "customerId", foreignField: "_id", as: "customerInfo" } }])The $lookup stage joins the orders collection with the customers collection using matching fields.
Fix the error in the query to embed multiple phone numbers inside a user document.
db.users.insertOne({ name: "Bob", phones: [1] })Embedding multiple phone numbers requires an array of objects, each with type and number fields.
Fill both blanks to write a $lookup that joins orders with products and filters only orders with quantity greater than 5.
db.orders.aggregate([{ $lookup: { from: "[1]", localField: "productId", foreignField: "_id", as: "productDetails" } }, { $match: { quantity: { [2]: 5 } } }])The $lookup joins with the products collection. The $match filters orders where quantity is greater than 5 using $gt.
Fill all three blanks to create a query that embeds a review inside a product document only if the rating is 4 or higher.
db.products.updateOne({ _id: [1] }, { $push: { reviews: { userId: [2], rating: [3] } } })The product _id and userId are ObjectIds. The rating must be 4 or higher, so 4 is used here.