Details
-
Improvement
-
Resolution: Duplicate
-
Minor - P4
-
None
-
None
-
Query
Description
Given the following collection:
{ _id : 0, grid : [ [ 0, 0, 0, 0 ], [ 0, 1, 0, 1 ], [ 0, 0, 0, 2 ], [ 1, 0, 2, 3 ] ] }
|
{ _id : 1, grid : [ [ 0, 0, 0, 0 ], [ 0, 0, 0, 2 ], [ 0, 0, 0, 4 ], [ 0, 0, 4, 5 ] ] }
|
one would expect to be able to transpose it as follows:
db.coll.aggregate({$project: { grid : { $zip: { inputs: "$grid" } } } })
|
However, this results in the following error:
2017-02-09T13:51:59.786-0500 E QUERY [thread1] Error: command failed: {
|
"ok" : 0,
|
"errmsg" : "inputs must be an array of expressions, found string",
|
"code" : 34461,
|
"codeName" : "Location34461"
|
} : aggregate failed :
|
So, the stage needs to be written instead as:
{
|
"$project" : {
|
"grid" : {
|
"$zip" : {
|
"inputs" : [
|
{ "$arrayElemAt" : [ "$grid", 0 ] },
|
{ "$arrayElemAt" : [ "$grid", 1 ] },
|
{ "$arrayElemAt" : [ "$grid", 2 ] },
|
{ "$arrayElemAt" : [ "$grid", 3 ] }
|
]
|
}
|
},
|
}
|
This is unexpected, more verbose, and only works for arrays with fixed dimensions.
Attachments
Issue Links
- duplicates
-
SERVER-31991 Allow n-ary aggregation expressions to compute their array of arguments dynamically
-
- Backlog
-
- related to
-
SERVER-31991 Allow n-ary aggregation expressions to compute their array of arguments dynamically
-
- Backlog
-