{
$unwind:
{
path: <field path>,
includeArrayIndex: <string>,
// to include documents whose sizes field is null, missing, or an empty array.
preserveNullAndEmptyArrays: <boolean>
}
}
unwind:
It is used for array attribute to show seprate result for that array.
// Inserted data :
db.inventory.insertOne({ "_id" : 1, "item" : "ABC1",
sizes: [ "S", "M", "L"] })
// unwind query
db.inventory.aggregate( [ { $unwind : "$sizes" } ] )
// output
{ "_id" : 1, "item" : "ABC1", "sizes" : "S" }
{ "_id" : 1, "item" : "ABC1", "sizes" : "M" }
{ "_id" : 1, "item" : "ABC1", "sizes" : "L" }
db.vehicledetails.aggregate([{$unwind : {path: "$model_year", preserveNullAndEmptyArrays: true}}]).pretty()
unwind mongodb