[SERVER-6436] Add method for unwinding nested arrays Created: 13/Jul/12  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Aaron Staple Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 4
Labels: expression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-23754 $unwind should error when it encounte... Backlog
is related to SERVER-23754 $unwind should error when it encounte... Backlog
is related to SERVER-40134 Distinct command against a view can r... Closed
Assigned Teams:
Query Execution
Participants:
Case:

 Description   

Right now $unwind can only unwind an array that is not nested within another array. For example 'a.b' can be unwound in this document:

{ a:{ b:[ 1, 2 ] } }
 
but not in this one:
 
{ a:[ { b:1 }, { b:2 } ] }
 
and not in this one:
 
{ a:[ { b:[ 1, 2 ] } ] }

Current behavior is to not unwind anything in these cases.



 Comments   
Comment by Evan Johnson [ 13/Mar/13 ]

I think some of these issues can be solved by using stacked $unwinds and $projects in the pipeline, like so:

db.foo.aggregate(

{ $unwind : "$a.b" }

,
{ $project : { "b" : "$a.b"}},

{ $unwind : "$b" }

,
{ $match:

{ "b": 1 }

}
);

Generated at Thu Feb 08 03:11:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.