Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-38454

Consider support for field renaming in $unwind stage

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Trivial - P5 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.

       

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            jeffm24 Jeffrey Mariconda
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: