[SERVER-73547] Allow collection-agnostic aggregation within $unionWith Created: 02/Feb/23  Updated: 03/Feb/23  Resolved: 02/Feb/23

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

Type: Improvement Priority: Major - P3
Reporter: Davis Haupt (Inactive) Assignee: Backlog - Query Optimization
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-58582 Create $documents stage and implement... Closed
Assigned Teams:
Query Optimization
Participants:

 Description   

Collection-agnostic aggregations that get their documents from a document-generating stage like $documents are sent to the server with aggregate: 1. There is currently no way to do this for a pipeline within a $unionWith stage, which will fail with a parse error if the specified collection is 1.

BSON field '$unionWith.coll' is the wrong type 'int', expected type 'string'

This ticket should enable pipelines like:

{
    aggregate: 1,
        pipeline:
            [
                {$documents: [{a: 1}]},
                {
                    $unionWith: {
                        coll: 1,
                        pipeline: [
                            {$documents: [{a: 2}]},
                        ]
                    }
                },
            ],
        cursor: {}
}



 Comments   
Comment by Davis Haupt (Inactive) [ 02/Feb/23 ]

The way to accomplish this is to simply leave off the coll parameter:

{
    aggregate: 1,
        pipeline:
            [
                {$documents: [{a: 1}]},
                {
                    $unionWith: {
                        pipeline: [
                            {$documents: [{a: 2}]},
                        ]
                    }
                },
            ],
        cursor: {}
}

Generated at Thu Feb 08 06:24:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.