...

Text file src/go.mongodb.org/mongo-driver/testdata/command-monitoring/find.yml

Documentation: go.mongodb.org/mongo-driver/testdata/command-monitoring

     1description: "find"
     2
     3schemaVersion: "1.15"
     4
     5createEntities:
     6  - client:
     7      id: &client client
     8      observeEvents:
     9        - commandStartedEvent
    10        - commandSucceededEvent
    11        - commandFailedEvent
    12  - database:
    13      id: &database database
    14      client: *client
    15      databaseName: &databaseName command-monitoring-tests
    16  - collection:
    17      id: &collection collection
    18      database: *database
    19      collectionName: &collectionName test
    20
    21_yamlAnchors:
    22  namespace: &namespace "command-monitoring-tests.test"
    23
    24initialData:
    25  - collectionName: *collectionName
    26    databaseName: *databaseName
    27    documents:
    28      - { _id: 1, x: 11 }
    29      - { _id: 2, x: 22 }
    30      - { _id: 3, x: 33 }
    31      - { _id: 4, x: 44 }
    32      - { _id: 5, x: 55 }
    33
    34tests:
    35  - description: "A successful find with no options"
    36    operations:
    37      - name: find
    38        object: *collection
    39        arguments:
    40          filter: { _id: 1 }
    41    expectEvents:
    42      - client: *client
    43        events:
    44          - commandStartedEvent:
    45              command:
    46                find: *collectionName
    47                filter: { _id: 1 }
    48              commandName: find
    49              databaseName: *databaseName
    50          - commandSucceededEvent:
    51              reply:
    52                ok: 1
    53                cursor:
    54                  id: 0
    55                  ns: *namespace
    56                  firstBatch:
    57                    -  { _id: 1, x: 11 }
    58              commandName: find
    59              databaseName: *databaseName
    60
    61  - description: "A successful find with options"
    62    operations:
    63      - name: find
    64        object: *collection
    65        arguments:
    66          filter: { _id: { $gt: 1 } }
    67          sort: { x: -1 }
    68          projection: { _id: 0, x: 1 }
    69          skip: 2
    70          comment: "test"
    71          hint: { _id: 1 }
    72          max: { _id: 6 }
    73          maxTimeMS: 6000
    74          min: { _id: 0 }
    75    expectEvents:
    76      - client: *client
    77        events:
    78          - commandStartedEvent:
    79              command:
    80                find: *collectionName
    81                filter: { _id: { $gt: 1 } }
    82                sort: { x: -1 }
    83                projection: { _id: 0, x: 1 }
    84                skip: 2
    85                comment: "test"
    86                hint: { _id: 1 }
    87                max: { _id: 6 }
    88                maxTimeMS: 6000
    89                min: { _id: 0 }
    90              commandName: find
    91              databaseName: *databaseName
    92          - commandSucceededEvent:
    93              reply:
    94                ok: 1
    95                cursor:
    96                  id: 0
    97                  ns: *namespace
    98                  firstBatch:
    99                    - { x: 33 }
   100                    - { x: 22 }
   101              commandName: find
   102              databaseName: *databaseName
   103
   104  - description: "A successful find with showRecordId and returnKey"
   105    operations:
   106      - name: find
   107        object: *collection
   108        arguments:
   109          filter: { }
   110          sort: { _id: 1 }
   111          showRecordId: true
   112          returnKey: true
   113    expectEvents:
   114      - client: *client
   115        events:
   116          - commandStartedEvent:
   117              command:
   118                find: *collectionName
   119                showRecordId: true
   120                returnKey: true
   121              commandName: find
   122              databaseName: *databaseName
   123          - commandSucceededEvent:
   124              reply:
   125                ok: 1
   126                cursor:
   127                  id: 0
   128                  ns: *namespace
   129                  firstBatch:
   130                    - { _id: 1 }
   131                    - { _id: 2 }
   132                    - { _id: 3 }
   133                    - { _id: 4 }
   134                    - { _id: 5 }
   135              commandName: find
   136              databaseName: *databaseName
   137
   138  - description: "A successful find with a getMore"
   139    operations:
   140      - name: find
   141        object: *collection
   142        arguments:
   143          filter: { _id: { $gte: 1 }}
   144          sort: { _id: 1 }
   145          batchSize: 3
   146    expectEvents:
   147      - client: *client
   148        events:
   149          - commandStartedEvent:
   150              command:
   151                find: *collectionName
   152                filter: { _id: { $gte: 1 }}
   153                sort: { _id: 1 }
   154                batchSize: 3
   155              commandName: find
   156              databaseName: *databaseName
   157          - commandSucceededEvent:
   158              reply:
   159                ok: 1
   160                cursor:
   161                  id: { $$type: [ int, long ] }
   162                  ns: *namespace
   163                  firstBatch:
   164                    - { _id: 1, x: 11 }
   165                    - { _id: 2, x: 22 }
   166                    - { _id: 3, x: 33 }
   167              commandName: find
   168              databaseName: *databaseName
   169          - commandStartedEvent:
   170              command:
   171                getMore: { $$type: [ int, long ] }
   172                collection: *collectionName
   173                batchSize: 3
   174              commandName: getMore
   175              databaseName: *databaseName
   176          - commandSucceededEvent:
   177              reply:
   178                ok: 1
   179                cursor:
   180                  id: 0
   181                  ns: *namespace
   182                  nextBatch:
   183                    - { _id: 4, x: 44 }
   184                    - { _id: 5, x: 55 }
   185              commandName: getMore
   186              databaseName: *databaseName
   187
   188  - description: "A successful find event with a getmore and the server kills the cursor (<= 4.4)"
   189    runOnRequirements:
   190      - minServerVersion: "3.1"
   191        maxServerVersion: "4.4.99"
   192        topologies: [ single, replicaset ]
   193    operations:
   194      - name: find
   195        object: *collection
   196        arguments:
   197          filter: { _id: { $gte: 1 } }
   198          sort: { _id: 1 }
   199          batchSize: 3
   200          limit: 4
   201    expectEvents:
   202      - client: *client
   203        events:
   204          - commandStartedEvent:
   205              command:
   206                find: *collectionName
   207                filter: { _id: { $gte: 1 } }
   208                sort: { _id: 1 }
   209                batchSize: 3
   210                limit: 4
   211              commandName: find
   212              databaseName: *databaseName
   213          - commandSucceededEvent:
   214              reply:
   215                ok: 1
   216                cursor:
   217                  id: { $$type: [ int, long ] }
   218                  ns: *namespace
   219                  firstBatch:
   220                    - { _id: 1, x: 11 }
   221                    - { _id: 2, x: 22 }
   222                    - { _id: 3, x: 33 }
   223              commandName: find
   224              databaseName: *databaseName
   225          - commandStartedEvent:
   226              command:
   227                getMore: { $$type: [ int, long ] }
   228                collection: *collectionName
   229                batchSize: 1
   230              commandName: getMore
   231              databaseName: *databaseName
   232          - commandSucceededEvent:
   233              reply:
   234                ok: 1
   235                cursor:
   236                  id: 0
   237                  ns: *namespace
   238                  nextBatch:
   239                    - { _id: 4, x: 44 }
   240              commandName: getMore
   241              databaseName: *databaseName
   242
   243  - description: "A failed find event"
   244    operations:
   245      - name: find
   246        object: *collection
   247        arguments:
   248          filter: { $or: true }
   249        expectError:
   250          isClientError: false
   251    expectEvents:
   252      - client: *client
   253        events:
   254          - commandStartedEvent:
   255              command:
   256                find: *collectionName
   257                filter: { $or: true }
   258              commandName: find
   259              databaseName: *databaseName
   260          - commandFailedEvent:
   261              commandName: find
   262              databaseName: *databaseName

View as plain text