...

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

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

     1description: aggregate-write-readPreference
     2
     3schemaVersion: '1.4'
     4
     5runOnRequirements:
     6  # 3.6+ non-standalone is needed to utilize $readPreference in OP_MSG
     7  - minServerVersion: "3.6"
     8    topologies: [ replicaset, sharded, load-balanced ]
     9
    10_yamlAnchors:
    11  readConcern: &readConcern
    12    level: &readConcernLevel "local"
    13  writeConcern: &writeConcern
    14    w: &writeConcernW 1
    15
    16createEntities:
    17  - client:
    18      id: &client0 client0
    19      observeEvents:
    20        - commandStartedEvent
    21      # Used to test that read and write concerns are still inherited
    22      uriOptions:
    23        readConcernLevel: *readConcernLevel
    24        w: *writeConcernW
    25  - database:
    26      id: &database0 database0
    27      client: *client0
    28      databaseName: &database0Name db0
    29  - collection:
    30      id: &collection0 collection0
    31      database: *database0
    32      collectionName: &collection0Name coll0
    33      collectionOptions:
    34        readPreference: &readPreference
    35          # secondaryPreferred is specified for compatibility with clusters that
    36          # may not have a secondary (e.g. each shard is only a primary).
    37          mode: secondaryPreferred
    38          # maxStalenessSeconds is specified to ensure that drivers forward the
    39          # read preference to mongos or a load balancer. That would not be the
    40          # case with only secondaryPreferred.
    41          maxStalenessSeconds: 600
    42  - collection:
    43      id: &collection1 collection1
    44      database: *database0
    45      collectionName: &collection1Name coll1
    46
    47initialData:
    48  - collectionName: *collection0Name
    49    databaseName: *database0Name
    50    documents:
    51      - { _id: 1, x: 11 }
    52      - { _id: 2, x: 22 }
    53      - { _id: 3, x: 33 }
    54  - collectionName: *collection1Name
    55    databaseName: *database0Name
    56    documents: []
    57
    58tests:
    59  - description: "Aggregate with $out includes read preference for 5.0+ server"
    60    runOnRequirements:
    61      - minServerVersion: "5.0"
    62        serverless: "forbid"
    63    operations:
    64      - object: *collection0
    65        name: aggregate
    66        arguments:
    67          pipeline: &outPipeline
    68            - { $match: { _id: { $gt: 1 } } }
    69            - { $sort: { x: 1 } }
    70            - { $out: *collection1Name }
    71    expectEvents:
    72      - client: *client0
    73        events:
    74          - commandStartedEvent:
    75              command:
    76                aggregate: *collection0Name
    77                pipeline: *outPipeline
    78                $readPreference: *readPreference
    79                readConcern: *readConcern
    80                writeConcern: *writeConcern
    81    outcome: &outcome
    82      - collectionName: *collection1Name
    83        databaseName: *database0Name
    84        documents:
    85          - { _id: 2, x: 22 }
    86          - { _id: 3, x: 33 }
    87
    88  - description: "Aggregate with $out omits read preference for pre-5.0 server"
    89    runOnRequirements:
    90      # MongoDB 4.2 introduced support for read concerns and write stages.
    91      # Pre-4.2 servers may allow a "local" read concern anyway, but some
    92      # drivers may avoid inheriting a client-level read concern for pre-4.2.
    93      - minServerVersion: "4.2"
    94        maxServerVersion: "4.4.99"
    95        serverless: "forbid"
    96    operations:
    97      - object: *collection0
    98        name: aggregate
    99        arguments:
   100          pipeline: *outPipeline
   101    expectEvents:
   102      - client: *client0
   103        events:
   104          - commandStartedEvent:
   105              command:
   106                aggregate: *collection0Name
   107                pipeline: *outPipeline
   108                $readPreference: { $$exists: false }
   109                readConcern: *readConcern
   110                writeConcern: *writeConcern
   111    outcome: *outcome
   112
   113  - description: "Aggregate with $merge includes read preference for 5.0+ server"
   114    runOnRequirements:
   115      - minServerVersion: "5.0"
   116    operations:
   117      - object: *collection0
   118        name: aggregate
   119        arguments:
   120          pipeline: &mergePipeline
   121            - { $match: { _id: { $gt: 1 } } }
   122            - { $sort: { x: 1 } }
   123            - { $merge: { into: *collection1Name } }
   124    expectEvents:
   125      - client: *client0
   126        events:
   127          - commandStartedEvent:
   128              command:
   129                aggregate: *collection0Name
   130                pipeline: *mergePipeline
   131                $readPreference: *readPreference
   132                readConcern: *readConcern
   133                writeConcern: *writeConcern
   134    outcome: *outcome
   135
   136  - description: "Aggregate with $merge omits read preference for pre-5.0 server"
   137    runOnRequirements:
   138      - minServerVersion: "4.2"
   139        maxServerVersion: "4.4.99"
   140    operations:
   141      - object: *collection0
   142        name: aggregate
   143        arguments:
   144          pipeline: *mergePipeline
   145    expectEvents:
   146      - client: *client0
   147        events:
   148          - commandStartedEvent:
   149              command:
   150                aggregate: *collection0Name
   151                pipeline: *mergePipeline
   152                $readPreference: { $$exists: false }
   153                readConcern: *readConcern
   154                writeConcern: *writeConcern
   155    outcome: *outcome

View as plain text