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

Add support for $replaceRoot aggregation stage

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      In some cases, the documents of interest in the aggregation pipeline are nested inside an outer document. For example, if I had a schema like this:

      {
        _id: "user_id",
        first: "first name",
        last: "last name",
        addresses: [
          {city: "New York", state: "NY", zip: "10036", address: "229 W 43rd"},
          {city: "Palo Alto", state: "CA", zip: "94301", address: "100 Forest Ave"}
          ...
        ]
      }
      

      Then I might have an aggregation pipeline which deals exclusively with the contents of 'addresses'. It's currently possible to do this, first by unwinding 'addresses', but this approach becomes annoying since all of the field names need to be prefixed with 'addresses.'. It would be useful to have some stage to promote the document inside 'addresses' to the top field. For example, something like this:

      db.users.aggregate([
        {$unwind: "$addresses"},
        {$transform: {root: "$addresses"}}
      ])
       
      {city: "New York", state: "NY", zip: "10036", address: "229 W 43rd"}
      {city: "Palo Alto", state: "CA", zip: "94301", address: "100 Forest Ave"}
      

      Such a stage could also support other transformations, like those possible in $project, or some that are not possible, such as adding a field to a document (SERVER-5781).

      Attachments

        Activity

          People

            robert@mongodb.com Robert Stam
            rathi.gnanasekaran Rathi Gnanasekaran
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: