Hướng dẫn unwind object mongodb
Docs Home → MongoDB Manual Show $unwind Deconstructs an array field from the input documents to output a document for each element. Each output document is the input document with the value of the array field replaced by the element. You can pass a field path operand or a document operand to unwind an array field. You can pass the array field path to
When you specify the field path, prefix
the field name with a dollar sign You can pass a document to
Changed in version 3.2: Previously, if a value in the field specified by the field path is not an array, If you specify a path
for a field that does not exist in an input document or the field is an empty array, To output documents where the array field is missing, null or an empty array, use the preserveNullAndEmptyArrays option. In
The
following aggregation uses the
The operation returns the following results:
Each document is identical to the input document except for the value of the Consider the
Expand the
The
NoteThe
The
The following
The output includes those documents where the
The following
The operation unwinds the
In
The following pipeline unwinds the First Stage:The Second Stage:The Third Stage:The
TipIn
The following operation groups the items sold by their tags and calculates the total sales amount per each tag. First StageThe first
Second StageThe second Third StageThe
Tip
|