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

Add a way to "unwind" fields in a document.

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None

      Example function:

      db.coll.insert({id: 'foo', a: 100, b: 200, c: 300, d: {e: 400, f:500}})
      db.coll.aggregate([
        {$docUnwind: {id: 0}},  // syntax similar to $project for whitelisting or blacklisting which fields to unwind
      ])
      {id: 'foo', f_name: 'a', f_value: 100}
      {id: 'foo', f_name: 'b', f_value: 200}
      {id: 'foo', f_name: 'c', f_value: 300}
      {id: 'foo', f_name: 'd.e', f_value: 400}
      {id: 'foo', f_name: 'd.f', f_value: 500}
      

      In short, it will take the fields in a document, and unwind a portion of them into name, value pairs, making a separate document for each.

      One use case for this is collecting statistics across a dynamic list of fields.

            Assignee:
            Unassigned Unassigned
            Reporter:
            rod.adams@mongodb.com Rod Adams
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: