[CSHARP-1742] Add support for $replaceRoot aggregation stage Created: 10/Aug/16  Updated: 27/May/22  Resolved: 28/Oct/16

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Rathi Gnanasekaran Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-23313 Add a $replaceRoot stage which allows... Closed
Epic Link: MongoDB 3.4
Server Compat: 3.3

 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).



 Comments   
Comment by Githook User [ 28/Oct/16 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1742: Added support for $replaceRoot aggregation stage.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/5d20d20b1973d0f6e6053e32ed99f6e00b73d31c

Comment by Hannes Magnusson [ 10/Aug/16 ]

Moved from CDRIVER-1373 to CSHARP-1595

Generated at Wed Feb 07 21:40:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.