Complete the code to unwind the 'items' array in the aggregation pipeline.
db.orders.aggregate([{ $[1]: "$items" }])The $unwind stage is used to flatten an array field in documents, creating a separate document for each element.
Complete the code to unwind the 'tags' array and preserve documents with empty or missing 'tags'.
db.products.aggregate([{ $unwind: { path: "$tags", [1]: true } }])The preserveNullAndEmptyArrays: true option keeps documents that have empty or missing arrays instead of removing them.
Fix the error in the unwind stage to correctly specify the array field path.
db.sales.aggregate([{ $unwind: "[1]" }])The $unwind stage requires the array field path as a string starting with a dollar sign, like "$items".
Fill both blanks to unwind the 'comments' array and include the array index as 'commentIndex'.
db.posts.aggregate([{ $unwind: { path: "$comments", [1]: "[2]" } }])The includeArrayIndex option adds the array element's index to each output document, and you can name this field, here as commentIndex.
Fill all three blanks to unwind the 'reviews' array, preserve empty arrays, and include the index as 'reviewPos'.
db.books.aggregate([{ $unwind: { path: "$reviews", [1]: true, [2]: "[3]" } }])This unwind stage flattens the 'reviews' array, keeps documents with empty or missing arrays, and adds the index of each review as 'reviewPos'.