mongodbHow to use unwind in MongoDB?
Unwind is an operator in MongoDB that allows you to deconstruct an array field from the input documents to output a document for each element in the array.
Example
db.collection.aggregate([
{
$unwind: "$arrayField"
}
])
Output example
{ _id: 1, arrayField: "a" }
{ _id: 1, arrayField: "b" }
{ _id: 1, arrayField: "c" }
Code explanation
$unwind
: the operator used to deconstruct the array fieldarrayField
: the array field to be deconstructed
Helpful links
More of Mongodb
- What is MongoDB default port?
- How to use watch in MongoDB?
- How to update many documents in MongoDB?
- How to list MongoDB users?
- How to remove a field from MongoDB?
- How to use MongoDB query with "or" condition?
- How to convert MongoDB ObjectId to string?
- How to use the limit operator in MongoDB?
- How to perform a health check for MongoDB?
- How to use triggers in MongoDB?
See more codes...