[SERVER-27964] $zip should accept array of arrays expression Created: 09/Feb/17  Updated: 06/Dec/22  Resolved: 20/Jun/19

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

Type: Improvement Priority: Minor - P4
Reporter: Geert Bosch Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 1
Labels: usability
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-31991 Allow n-ary aggregation expressions t... Backlog
Related
related to SERVER-31991 Allow n-ary aggregation expressions t... Backlog
Assigned Teams:
Query
Participants:

 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.



 Comments   
Comment by David Storch [ 05/Jun/19 ]

asya, should we close this as a duplicate of the more general ticket given your point above?

Comment by Asya Kamsky [ 30/May/19 ]

SERVER-31991 is asking for a general solution to this specific problem.

Generated at Thu Feb 08 04:16:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.