[SERVER-73888] Aggregation Pipeline: $unwind always gives an empty result with nested fields Created: 10/Feb/23 Updated: 10/Feb/23 Resolved: 10/Feb/23 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Blocker - P1 |
| Reporter: | Johnny Shields | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
|||||||||||||||
| Operating System: | ALL | |||||||||||||||
| Steps To Reproduce: | Given the following documents:
|
|||||||||||||||
| Participants: | ||||||||||||||||
| Description |
|
When using the AggregationPipeline, $unwind always gives an empty result with nested fields
Adding a $project stage will fix the issue:
Refer to Steps to Reproduce below for details. |
| Comments |
| Comment by Johnny Shields [ 10/Feb/23 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
As noted above:
In your result with preserveNullAndEmptyArrays = true, you get "_id" as an array like this:
it should be:
in two separate rows, i.e. "$unwind"ed. Anyway, its fine to close this ticket as a dupe of SERVER-59713. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alex Bevilacqua [ 10/Feb/23 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
shields@tablecheck.com I apparently jumped the gun on the repro as I was testing to ensure the pipeline didn't return an empty result:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Johnny Shields [ 10/Feb/23 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
You are correct that this is a duplicate of SERVER-59713 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Johnny Shields [ 10/Feb/23 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Alex, I have tried this and it does not work.
Please post the result of your aggregation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alex Bevilacqua [ 10/Feb/23 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
shields@tablecheck.com I think this actually works as designed. You can pass the path when you're unwinding an array field path to produce the desired result you've described without needing the $project to a temporary field first. For example:
I'm going to close this ticket out as it appears to duplicate SERVER-59713 which describes a similar issue. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Johnny Shields [ 10/Feb/23 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Note that other operators such as $group handle nested.fields fine, so I consider this to be a possible bug. |