[SERVER-23313] Add a $replaceRoot stage which allows promoting a sub-document to the top level Created: 23/Mar/16 Updated: 03/May/17 Resolved: 29/Jul/16 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | None |
| Fix Version/s: | 3.3.11 |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Charlie Swanson | Assignee: | Carly Robison |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||||||||||||||||||||||||||
| Sprint: | Integration 18 (08/05/16) | ||||||||||||||||||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||||||||||||||||||
| Description |
Syntax
Examples
More Details
Original DescriptionIn 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:
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:
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 ( |
| Comments |
| Comment by Asya Kamsky [ 07/Aug/16 ] | ||
|
Also they might correct such errors via checking $type of path (in addition or instead of $ifNull) to fill in default values... | ||
| Comment by Asya Kamsky [ 07/Aug/16 ] | ||
|
I don't think this error message is always correct/helpful:
If the field (say "$a") is not an object we correctly say
Is there a reason not to always say that even if the field is missing? Also if path is missing or there but null they don't need to match, they might need to $ifNull inside newRoot, maybe to preserve document counts or fill in some default values. | ||
| Comment by Charlie Swanson [ 29/Jul/16 ] | ||
|
Moving "Driver Changes" back to "Needed". It's my understanding that there are some drivers which provide shortcuts/helpers in their language(s) to make it easier to construct aggregation stages and expressions. They need to implement new helpers for new stages/expressions/accumulators. | ||
| Comment by Githook User [ 29/Jul/16 ] | ||
|
Author: {u'username': u'carlyrobison', u'name': u'Carly Robison', u'email': u'crobison@caltech.edu'}Message: replaceRoot promotes a subdocument to the top level | ||
| Comment by Asya Kamsky [ 01/Jul/16 ] | ||
|
I think the issue isn't that it's annoying to deal with fields being prefixed with "addresses." but rather that there is no way to transform them to the top level except by knowing every single field at the top level and within subdocument. | ||
| Comment by Charlie Swanson [ 23/Mar/16 ] | ||
|
To be determined. Probably lost by default, unless explicitly included via some syntax I haven't decided about yet. Maybe something like:
Would include the _id, but not first or last. | ||
| Comment by Scott Hernandez (Inactive) [ 23/Mar/16 ] | ||
|
What about the other fields in the original document, like "_id", "first", "last"? Are they lost or should they be included in the new documents? |