...

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

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

     1description: "estimatedDocumentCount"
     2
     3schemaVersion: "1.0"
     4
     5createEntities:
     6  - client:
     7      id: &client0 client0
     8      useMultipleMongoses: false # Avoid setting fail points with multiple mongoses
     9      uriOptions: { retryReads: false } # Avoid retrying fail points with closeConnection
    10      observeEvents: [ commandStartedEvent ]
    11  - database:
    12      id: &database0 database0
    13      client: *client0
    14      databaseName: &database0Name edc-tests
    15  - collection:
    16      id: &collection0 collection0
    17      database: *database0
    18      collectionName: &collection0Name coll0
    19  - collection:
    20      # Nonexistent collection intentionally omitted from initialData
    21      id: &collection1 collection1
    22      database: *database0
    23      collectionName: &collection1Name coll1
    24  - collection:
    25      id: &collection0View collection0View
    26      database: *database0
    27      collectionName: &collection0ViewName coll0view
    28
    29initialData:
    30  - collectionName: *collection0Name
    31    databaseName: *database0Name
    32    documents:
    33      - { _id: 1, x: 11 }
    34      - { _id: 2, x: 22 }
    35      - { _id: 3, x: 33 }
    36
    37tests:
    38  - description: "estimatedDocumentCount always uses count"
    39    operations:
    40      - name: estimatedDocumentCount
    41        object: *collection0
    42        expectResult: 3
    43    expectEvents:
    44      - client: *client0
    45        events:
    46          - commandStartedEvent:
    47              command:
    48                count: *collection0Name
    49              commandName: count
    50              databaseName: *database0Name
    51
    52  - description: "estimatedDocumentCount with maxTimeMS"
    53    operations:
    54      - name: estimatedDocumentCount
    55        object: *collection0
    56        arguments:
    57          maxTimeMS: 6000
    58        expectResult: 3
    59    expectEvents:
    60      - client: *client0
    61        events:
    62          - commandStartedEvent:
    63              command:
    64                count: *collection0Name
    65                maxTimeMS: 6000
    66              commandName: count
    67              databaseName: *database0Name
    68
    69  - description: "estimatedDocumentCount on non-existent collection"
    70    operations:
    71      - name: estimatedDocumentCount
    72        object: *collection1
    73        expectResult: 0
    74    expectEvents:
    75      - client: *client0
    76        events:
    77          - commandStartedEvent:
    78              command:
    79                count: *collection1Name
    80              commandName: count
    81              databaseName: *database0Name
    82
    83  - description: "estimatedDocumentCount errors correctly--command error"
    84    runOnRequirements:
    85      - minServerVersion: "4.0.0"
    86        topologies: [ single, replicaset ]
    87      - minServerVersion: "4.2.0"
    88        topologies: [ sharded ]
    89    operations:
    90      - name: failPoint
    91        object: testRunner
    92        arguments:
    93          client: *client0
    94          failPoint:
    95            configureFailPoint: failCommand
    96            mode: { times: 1 }
    97            data:
    98              failCommands: [ count ]
    99              errorCode: 8 # UnknownError
   100      - name: estimatedDocumentCount
   101        object: *collection0
   102        expectError:
   103          errorCode: 8 # UnknownError
   104    expectEvents:
   105      - client: *client0
   106        events:
   107          - commandStartedEvent:
   108              command:
   109                count: *collection0Name
   110              commandName: count
   111              databaseName: *database0Name
   112
   113  - description: "estimatedDocumentCount errors correctly--socket error"
   114    runOnRequirements:
   115      - minServerVersion: "4.0.0"
   116        topologies: [ single, replicaset ]
   117      - minServerVersion: "4.2.0"
   118        topologies: [ sharded ]
   119    operations:
   120      - name: failPoint
   121        object: testRunner
   122        arguments:
   123          client: *client0
   124          failPoint:
   125            configureFailPoint: failCommand
   126            mode: { times: 1 }
   127            data:
   128              failCommands: [ count ]
   129              closeConnection: true
   130      - name: estimatedDocumentCount
   131        object: *collection0
   132        expectError:
   133          isError: true
   134    expectEvents:
   135      - client: *client0
   136        events:
   137          - commandStartedEvent:
   138              command:
   139                count: *collection0Name
   140              commandName: count
   141              databaseName: *database0Name
   142
   143  - description: "estimatedDocumentCount works correctly on views"
   144    # viewOn option was added to the create command in 3.4
   145    runOnRequirements:
   146      - minServerVersion: "3.4.0"
   147    operations:
   148      - name: dropCollection
   149        object: *database0
   150        arguments:
   151          collection: *collection0ViewName
   152      - name: createCollection
   153        object: *database0
   154        arguments:
   155          collection: *collection0ViewName
   156          viewOn: *collection0Name
   157          pipeline: &pipeline
   158            - { $match: { _id: { $gt: 1 } } }
   159      - name: estimatedDocumentCount
   160        object: *collection0View
   161        expectResult: 2
   162    expectEvents:
   163      - client: *client0
   164        events:
   165          - commandStartedEvent:
   166              command:
   167                drop: *collection0ViewName
   168              commandName: drop
   169              databaseName: *database0Name
   170          - commandStartedEvent:
   171              command:
   172                create: *collection0ViewName
   173                viewOn: *collection0Name
   174                pipeline: *pipeline
   175              commandName: create
   176              databaseName: *database0Name
   177          - commandStartedEvent:
   178              command:
   179                count: *collection0ViewName
   180              commandName: count
   181              databaseName: *database0Name

View as plain text