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
- How to work with time series data in MongoDB?
- How to empty an array in MongoDB?
- How to use watch in MongoDB?
- How to check the version of MongoDB?
- How to use MongoDB pull?
- How to create a many to many relation in MongoDB?
- How to rename a field in MongoDB?
- How to kill an operation in MongoDB?
- How to check if array is empty in MongoDB?
- How to join two collections in MongoDB?
See more codes...