UnionWith constructor

UnionWith({
  1. required String coll,
  2. List<AggregationStage>? pipeline,
})

Creates $UnionWith stage with it's own pipeline

  • coll - The collection or view whose pipeline results you wish to include in the result set.

  • pipeline - Optional. An aggregation pipeline to apply to the specified coll. <stage1>, <stage2>, ... The pipeline cannot include the $out and $merge stages.

    The combined results from the previous stage and the $unionWith stage can include duplicates.

NOTE:

The $unionWith operation would correspond to the following SQL statement:

   SELECT *
  FROM Collection1
  WHERE ...
  UNION ALL
  SELECT *
  FROM Collection2
  WHERE ...

The pipeline cannot directly access the input document fields. Instead, first define the variables for the input document fields, and then reference the variables in the stages in the pipeline.

  • as - Specifies the name of the new array field to add to the input documents. The new array field contains the matching documents from the from collection. If the specified name already exists in the input document, the existing field is overwritten.

Implementation

UnionWith({required String coll, List<AggregationStage>? pipeline})
    : super(
          'unionWith',
          AEObject({
            'coll': coll,
            if (pipeline != null) 'pipeline': AEList(pipeline),
          }));