Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1939

Add an aggregation expression to convert an object to an array of key, value pairs

    • Type: Icon: New Feature New Feature
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: API
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      In many cases, it would be useful to convert an object to an array. We should add an aggregation expression to do so. For example, it could be called $objectToArray, and do something like this:

      > db.foo.insert({_id: 0, subDoc: {a: 1, b: 3, c: "example"}});
      > db.foo.aggregate([{$project: {expanded: {$objectToArray: "$subDoc"}}}])
      {_id: 0, expanded: [{k: "a", v: 1}, {k: "b", v: 3}, {k: "c", v: "example"}]}
      
      Original Description

      Currently, if a collection contains the following document:

      {_id: 0, data: {a: 1, b: 2, c: 3}}
      

      There is no way to unwind that one document into the following three documents:

      {_id: 0, data: {a: 1}}
      {_id: 0, data: {b: 2}}
      {_id: 0, data: {c: 3}}
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            rathi.gnanasekaran Rathi Gnanasekaran
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: