[SERVER-23201] provide union operator to union two collections (or more) Created: 17/Mar/16  Updated: 06/Dec/22  Resolved: 20/Apr/20

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

Type: New Feature Priority: Major - P3
Reporter: Asya Kamsky Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 31
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-45712 Remove flag guard for $unionWith Closed
Duplicate
duplicates SERVER-45712 Remove flag guard for $unionWith Closed
is duplicated by SERVER-33788 db.createView to allow UNION of multi... Closed
is duplicated by SERVER-25434 $lookup: allow option for FULL outer-... Closed
Related
is related to SERVER-44878 Support to read and write to/from a p... Backlog
Assigned Teams:
Query
Participants:
Case:

 Description   

This is similar to SQL UNION where two selects/finds combine their results as if from one entity.

SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;



 Comments   
Comment by Charlie Swanson [ 20/Apr/20 ]

Hi all. We are pleased to announce that a new aggregation stage $unionWith will be available in the 4.4 release. Here's one example, with more to come in documentation soon.

db.example.aggregate([
    // Can have other stages here.
    {$unionWith: {
      coll: "otherCollectionName",
      pipeline: [ /* Pipeline which will operator over "otherCollectionName" */ ]
    }},
    // Can have other stages here, applied to data from both "example" and "otherCollectionName".
]);

There is also a shorthand syntax when you don't need a sub-pipeline:

db.example.aggregate([
    // Can have other stages here.
    {$unionWith: "otherCollectionName"},
    // Can have other stages here, applied to data from both "example" and "otherCollectionName".
]);

Comment by Saju [ 12/Oct/18 ]

Am also waiting for "Full Join", when we can expect ?

Comment by Devendra Chauhan [ 20/Nov/17 ]

In which version of MongoDB functionality similar to "Full Join" will be available?
Thanks
Devendra

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