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

Consider support for field renaming in $unwind stage

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Trivial - P5 Trivial - P5
    • None
    • None
    • Aggregation Framework
    • None
    • Query Optimization

    Description

      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.

       

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            jeffm24 Jeffrey Mariconda
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated: