...

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

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

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

View as plain text