[CSHARP-1620] aggregation: Should have a $zip operator to combine arrays Created: 06/Apr/16  Updated: 27/May/22  Resolved: 31/Aug/16

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: None
Fix Version/s: 2.4

Type: New Feature Priority: Major - P3
Reporter: Rathi Gnanasekaran Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-20163 aggregation: Should have a $zip opera... Closed
is depended on by DRIVERS-297 Aggregation Framework Support for 3.4 Closed
Epic Link: MongoDB 3.4
Server Compat: 3.3

 Description   

Syntax

{
    $zip: {
        inputs: <array of expressions>
        defaults: <array of expressions>   
        useLongestLength: <bool - default false, cannot specify defaults if false>
    }
}

Example

Input

{_id: 0, evens: [0, 2, 4, 6], odds: [1, 3, 5]}
{_id: 1, evens: [4], odds: [1, 3]}

Pipeline

db.coll.aggregate([{
    $project: {
        z: {
            $zip: {
                inputs: ["$evens", "$odds"],
                defaults: [0, 1],
                useLongestLength: true
            }
        }
    }
}])

Output

{_id: 0, z: [[0, 1], [2, 3], [4, 5], [6, 1]]}
{_id: 1, z: [[4, 1], [0, 3]]}

Additional Notes

  • Uses length of shortest array, unless useLongestLength is true. If useLongestLength is true, but defaults is not specified, will use null to fill in.
  • The use of null here is consistent with our parsing of array literals (e.g. [0, "$field"] will become [0, null] if 'field' does not exist).
  • 'defaults' cannot be specified unless useLongestLength is true.
  • If any input is null, will return null. $map returns null if its input is nullish.
  • Will error if any input is not an array (and is not nullish).
  • Will error if 'defaults' is specified without 'useLongestLength', or is not the same length as 'inputs'.


 Comments   
Comment by Githook User [ 29/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1620: added support for $zip.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/2d0293151202a85e457582f1f5c153b5c20e0966

Comment by Githook User [ 24/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1620: added support for $zip.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/2d0293151202a85e457582f1f5c153b5c20e0966

Comment by Githook User [ 21/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1620: added support for $zip.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/0b9439421fb85bc7ade4181e33e49608377e7d02

Comment by Githook User [ 16/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1620: added support for $zip.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/8ed7779965981c211914b25a37eb7113ae18387d

Comment by Githook User [ 31/Aug/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1620: added support for $zip.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/086b79250c2a9a012270ffab7adbf1b6254e82e2

Comment by Githook User [ 29/Aug/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1620: added support for $zip.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/1a5caa250ad25cfe7922cb094d5a3a3d6a1ee6f2

Comment by Githook User [ 24/Aug/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1620: added support for $zip.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/7d3fa6ae6ae10f1376998c889c1dc24d011d7755

Generated at Wed Feb 07 21:40:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.