...

Text file src/go.mongodb.org/mongo-driver/testdata/crud/unified/aggregate-let.yml

Documentation: go.mongodb.org/mongo-driver/testdata/crud/unified

     1description: "aggregate-let"
     2
     3schemaVersion: "1.4"
     4
     5createEntities:
     6  - client:
     7      id: &client0 client0
     8      observeEvents: [ commandStartedEvent ]
     9  - database:
    10      id: &database0 database0
    11      client: *client0
    12      databaseName: &database0Name crud-tests
    13  - collection:
    14      id: &collection0 collection0
    15      database: *database0
    16      collectionName: &collection0Name coll0
    17  - collection:
    18      id: &collection1 collection1
    19      database: *database0
    20      collectionName: &collection1Name coll1
    21
    22initialData: &initialData
    23  - collectionName: *collection0Name
    24    databaseName: *database0Name
    25    documents:
    26      - { _id: 1 }
    27  - collectionName: *collection1Name
    28    databaseName: *database0Name
    29    documents: [ ]
    30
    31tests:
    32  - description: "Aggregate with let option"
    33    runOnRequirements:
    34      - minServerVersion: "5.0"
    35    operations:
    36      - name: aggregate
    37        object: *collection0
    38        arguments:
    39          pipeline: &pipeline0
    40            # $match takes a query expression, so $expr is necessary to utilize
    41            # an aggregate expression context and access "let" variables.
    42            - $match: { $expr: { $eq: ["$_id", "$$id"] } }
    43            - $project: { _id: 0, x: "$$x", y: "$$y", rand: "$$rand" }
    44          # Values in "let" must be constant or closed expressions that do not
    45          # depend on document values. This test demonstrates a basic constant
    46          # value, a value wrapped with $literal (to avoid expression parsing),
    47          # and a closed expression (e.g. $rand).
    48          let: &let0
    49            id: 1
    50            x: foo
    51            y: { $literal: "$bar" }
    52            rand: { $rand: {} }
    53        expectResult:
    54          - { x: "foo", y: "$bar", rand: { $$type: "double" } }
    55    expectEvents:
    56      - client: *client0
    57        events:
    58          - commandStartedEvent:
    59              command:
    60                aggregate: *collection0Name
    61                pipeline: *pipeline0
    62                let: *let0
    63
    64  - description: "Aggregate with let option unsupported (server-side error)"
    65    runOnRequirements:
    66      - minServerVersion: "2.6.0"
    67        maxServerVersion: "4.4.99"
    68    operations:
    69      - name: aggregate
    70        object: *collection0
    71        arguments:
    72          pipeline: &pipeline1
    73            - $match: { _id: 1 }
    74          let: &let1
    75            x: foo
    76        expectError:
    77          # Older server versions may not report an error code, but the error
    78          # message is consistent between 2.6.x and 4.4.x server versions.
    79          errorContains: "unrecognized field 'let'"
    80          isClientError: false
    81    expectEvents:
    82      - client: *client0
    83        events:
    84          - commandStartedEvent:
    85              command:
    86                aggregate: *collection0Name
    87                pipeline: *pipeline1
    88                let: *let1
    89
    90  - description: "Aggregate to collection with let option"
    91    runOnRequirements:
    92      - minServerVersion: "5.0"
    93        serverless: "forbid"
    94    operations:
    95      - name: aggregate
    96        object: *collection0
    97        arguments:
    98          pipeline: &pipeline2
    99            - $match: { $expr: { $eq: ["$_id", "$$id"] } }
   100            - $project: { _id: 1 }
   101            - $out: *collection1Name
   102          let: &let2
   103            id: 1
   104    expectEvents:
   105      - client: *client0
   106        events:
   107          - commandStartedEvent:
   108              command:
   109                aggregate: *collection0Name
   110                pipeline: *pipeline2
   111                let: *let2
   112    outcome:
   113      - collectionName: *collection1Name
   114        databaseName: *database0Name
   115        documents:
   116          - { _id: 1 }
   117
   118  - description: "Aggregate to collection with let option unsupported (server-side error)"
   119    runOnRequirements:
   120      - minServerVersion: "2.6.0"
   121        maxServerVersion: "4.4.99"
   122    operations:
   123      - name: aggregate
   124        object: *collection0
   125        arguments:
   126          pipeline: *pipeline2
   127          let: *let2
   128        expectError:
   129          errorContains: "unrecognized field 'let'"
   130          isClientError: false
   131    expectEvents:
   132      - client: *client0
   133        events:
   134          - commandStartedEvent:
   135              command:
   136                aggregate: *collection0Name
   137                pipeline: *pipeline2
   138                let: *let2

View as plain text