-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Trivial - P5
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
-
Query Optimization
In my experience, array fields in documents are usually labeled as plural (e.g. items: ['item']). This becomes a little confusing to read once they are past the $unwind stage because the value will become singular but the field name remains plural. This can be alleviated via an $addFields stage directly after the $unwind, but that seems inefficient.
A potential solution here could be to add an 'as' option to the $unwind stage like the following:
{ $unwind: { path: '$items', as: 'item' } }
This would $unwind and rename the unwound field to the specified name in a single stage, and it is consistent with the naming conventions of expressions like $filter.