...

Text file src/go.mongodb.org/mongo-driver/testdata/crud/v1/write/bulkWrite.yml

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

     1data:
     2    - {_id: 1, x: 11}
     3    - {_id: 2, x: 22}
     4
     5minServerVersion: '2.6'
     6
     7tests:
     8    -
     9        description: "BulkWrite with deleteOne operations"
    10        operation:
    11            name: "bulkWrite"
    12            arguments:
    13                # Note: as in the "DeleteOne when many documents match" test in
    14                # deleteOne.yml, we omit a deleteOne operation that might match
    15                # multiple documents as that would hinder our ability to assert
    16                # the final state of the collection under test.
    17                requests:
    18                    -
    19                        # does not match an existing document
    20                        name: "deleteOne"
    21                        arguments:
    22                            filter: { _id: 3 }
    23                    -
    24                        # deletes the matched document
    25                        name: "deleteOne"
    26                        arguments:
    27                            filter: { _id: 2 }
    28                options: { ordered: true }
    29        outcome:
    30            result:
    31                deletedCount: 1
    32                insertedCount: 0
    33                insertedIds: {}
    34                matchedCount: 0
    35                modifiedCount: 0
    36                upsertedCount: 0
    37                upsertedIds: {}
    38            collection:
    39                data:
    40                    - {_id: 1, x: 11 }
    41    -
    42        description: "BulkWrite with deleteMany operations"
    43        operation:
    44            name: "bulkWrite"
    45            arguments:
    46                requests:
    47                    -
    48                        # does not match any existing documents
    49                        name: "deleteMany"
    50                        arguments:
    51                            filter: { x: { $lt: 11 } }
    52                    -
    53                        # deletes the matched documents
    54                        name: "deleteMany"
    55                        arguments:
    56                            filter: { x: { $lte: 22 } }
    57                options: { ordered: true }
    58        outcome:
    59            result:
    60                deletedCount: 2
    61                insertedCount: 0
    62                insertedIds: {}
    63                matchedCount: 0
    64                modifiedCount: 0
    65                upsertedCount: 0
    66                upsertedIds: {}
    67            collection:
    68                data: []
    69    -
    70        description: "BulkWrite with insertOne operations"
    71        operation:
    72            name: "bulkWrite"
    73            arguments:
    74                requests:
    75                    -
    76                        name: "insertOne"
    77                        arguments:
    78                            document: { _id: 3, x: 33 }
    79                    -
    80                        name: "insertOne"
    81                        arguments:
    82                            document: { _id: 4, x: 44 }
    83                options: { ordered: true }
    84        outcome:
    85            result:
    86                deletedCount: 0
    87                insertedCount: 2
    88                insertedIds: { 0: 3, 1: 4 }
    89                matchedCount: 0
    90                modifiedCount: 0
    91                upsertedCount: 0
    92                upsertedIds: {}
    93            collection:
    94                data:
    95                    - {_id: 1, x: 11 }
    96                    - {_id: 2, x: 22 }
    97                    - {_id: 3, x: 33 }
    98                    - {_id: 4, x: 44 }
    99    -
   100        description: "BulkWrite with replaceOne operations"
   101        operation:
   102            name: "bulkWrite"
   103            arguments:
   104                # Note: as in the "ReplaceOne when many documents match" test in
   105                # replaceOne.yml, we omit a replaceOne operation that might
   106                # match multiple documents as that would hinder our ability to
   107                # assert the final state of the collection under test.
   108                requests:
   109                    -
   110                        # does not match an existing document
   111                        name: "replaceOne"
   112                        arguments:
   113                            filter: { _id: 3 }
   114                            replacement: { x: 33 }
   115                    -
   116                        # modifies the matched document
   117                        name: "replaceOne"
   118                        arguments:
   119                            filter: { _id: 1 }
   120                            replacement: { x: 12 }
   121                    -
   122                        # does not match an existing document and upserts
   123                        name: "replaceOne"
   124                        arguments:
   125                            filter: { _id: 3 }
   126                            replacement: { x: 33 }
   127                            upsert: true
   128                options: { ordered: true }
   129        outcome:
   130            result:
   131                deletedCount: 0
   132                insertedCount: 0
   133                insertedIds: {}
   134                matchedCount: 1
   135                modifiedCount: 1
   136                upsertedCount: 1
   137                upsertedIds: { 2: 3 }
   138            collection:
   139                data:
   140                    - {_id: 1, x: 12 }
   141                    - {_id: 2, x: 22 }
   142                    - {_id: 3, x: 33 }
   143    -
   144        description: "BulkWrite with updateOne operations"
   145        operation:
   146            name: "bulkWrite"
   147            arguments:
   148                # Note: as in the "UpdateOne when many documents match" test in
   149                # updateOne.yml, we omit an updateOne operation that might match
   150                # multiple documents as that would hinder our ability to assert
   151                # the final state of the collection under test.
   152                requests:
   153                    -
   154                        # does not match an existing document
   155                        name: "updateOne"
   156                        arguments:
   157                            filter: { _id: 0 }
   158                            update: { $set: { x: 0 } }
   159                    -
   160                        # does not modify the matched document
   161                        name: "updateOne"
   162                        arguments:
   163                            filter: { _id: 1 }
   164                            update: { $set: { x: 11 } }
   165                    -
   166                        # modifies the matched document
   167                        name: "updateOne"
   168                        arguments:
   169                            filter: { _id: 2 }
   170                            update: { $inc: { x: 1 } }
   171                    -
   172                        # does not match an existing document and upserts
   173                        name: "updateOne"
   174                        arguments:
   175                            filter: { _id: 3 }
   176                            update: { $set: { x: 33 } }
   177                            upsert: true
   178                options: { ordered: true }
   179        outcome:
   180            result:
   181                deletedCount: 0
   182                insertedCount: 0
   183                insertedIds: {}
   184                matchedCount: 2
   185                modifiedCount: 1
   186                upsertedCount: 1
   187                upsertedIds: { 3: 3 }
   188            collection:
   189                data:
   190                    - {_id: 1, x: 11 }
   191                    - {_id: 2, x: 23 }
   192                    - {_id: 3, x: 33 }
   193    -
   194        description: "BulkWrite with updateMany operations"
   195        operation:
   196            name: "bulkWrite"
   197            arguments:
   198                requests:
   199                    -
   200                        # does not match any existing documents
   201                        name: "updateMany"
   202                        arguments:
   203                            filter: { x: { $lt: 11 } }
   204                            update: { $set: { x: 0 } }
   205                    -
   206                        # does not modify the matched documents
   207                        name: "updateMany"
   208                        arguments:
   209                            filter: { x: { $lte: 22 } }
   210                            update: { $unset: { y: 1 } }
   211                    -
   212                        # modifies the matched documents
   213                        name: "updateMany"
   214                        arguments:
   215                            filter: { x: { $lte: 22 } }
   216                            update: { $inc: { x: 1 } }
   217                    -
   218                        # does not match any existing documents and upserts
   219                        name: "updateMany"
   220                        arguments:
   221                            filter: { _id: 3 }
   222                            update: { $set: { x: 33 } }
   223                            upsert: true
   224                options: { ordered: true }
   225        outcome:
   226            result:
   227                deletedCount: 0
   228                insertedCount: 0
   229                insertedIds: {}
   230                matchedCount: 4
   231                modifiedCount: 2
   232                upsertedCount: 1
   233                upsertedIds: { 3: 3 }
   234            collection:
   235                data:
   236                    - {_id: 1, x: 12 }
   237                    - {_id: 2, x: 23 }
   238                    - {_id: 3, x: 33 }
   239    -
   240        description: "BulkWrite with mixed ordered operations"
   241        operation:
   242            name: "bulkWrite"
   243            arguments:
   244                requests:
   245                    -
   246                        name: "insertOne"
   247                        arguments:
   248                            document: { _id: 3, x: 33 }
   249                    -
   250                        name: "updateOne"
   251                        arguments:
   252                            filter: { _id: 2 }
   253                            update: { $inc: { x: 1 } }
   254                    -
   255                        name: "updateMany"
   256                        arguments:
   257                            filter: { _id: { $gt: 1 } }
   258                            update: { $inc: { x: 1 } }
   259                    -
   260                        name: "insertOne"
   261                        arguments:
   262                            document: { _id: 4, x: 44 }
   263                    -
   264                        name: "deleteMany"
   265                        arguments:
   266                            filter: { x: { $nin: [ 24, 34 ] } }
   267                    -
   268                        name: "replaceOne"
   269                        arguments:
   270                            filter: { _id: 4 }
   271                            replacement: { _id: 4, x: 44 }
   272                            upsert: true
   273                options: { ordered: true }
   274        outcome:
   275            result:
   276                deletedCount: 2
   277                insertedCount: 2
   278                insertedIds: { 0: 3, 3: 4 }
   279                matchedCount: 3
   280                modifiedCount: 3
   281                upsertedCount: 1
   282                upsertedIds: { 5: 4 }
   283            collection:
   284                data:
   285                    - {_id: 2, x: 24 }
   286                    - {_id: 3, x: 34 }
   287                    - {_id: 4, x: 44 }
   288    -
   289        description: "BulkWrite with mixed unordered operations"
   290        operation:
   291            name: "bulkWrite"
   292            arguments:
   293                # We omit inserting multiple documents and updating documents
   294                # that may not exist at the start of this test as we cannot
   295                # assume the order in which the operations will execute.
   296                requests:
   297                    -
   298                        name: "replaceOne"
   299                        arguments:
   300                            filter: { _id: 3 }
   301                            replacement: { _id: 3, x: 33 }
   302                            upsert: true
   303                    -
   304                        name: "deleteOne"
   305                        arguments:
   306                            filter: { _id: 1 }
   307                    -
   308                        name: "updateOne"
   309                        arguments:
   310                            filter: { _id: 2 }
   311                            update: { $inc: { x: 1 } }
   312                options: { ordered: false }
   313        outcome:
   314            result:
   315                deletedCount: 1
   316                insertedCount: 0
   317                insertedIds: {}
   318                matchedCount: 1
   319                modifiedCount: 1
   320                upsertedCount: 1
   321                upsertedIds: { 0: 3 }
   322            collection:
   323                data:
   324                    - {_id: 2, x: 23 }
   325                    - {_id: 3, x: 33 }
   326    -
   327        description: "BulkWrite continue-on-error behavior with unordered (preexisting duplicate key)"
   328        operation:
   329            name: "bulkWrite"
   330            arguments:
   331                requests:
   332                    -
   333                        name: "insertOne"
   334                        arguments:
   335                            document: { _id: 2, x: 22 }
   336                    -
   337                        name: "insertOne"
   338                        arguments:
   339                            document: { _id: 3, x: 33 }
   340                    -
   341                        name: "insertOne"
   342                        arguments:
   343                            document: { _id: 4, x: 44 }
   344                options: { ordered: false }
   345        outcome:
   346            error: true
   347            result:
   348                deletedCount: 0
   349                insertedCount: 2
   350                # Since the map of insertedIds is generated before execution it
   351                # could indicate inserts that did not actually succeed. We omit
   352                # this field rather than expect drivers to provide an accurate
   353                # map filtered by write errors.
   354                matchedCount: 0
   355                modifiedCount: 0
   356                upsertedCount: 0
   357                upsertedIds: { }
   358            collection:
   359                data:
   360                    - { _id: 1, x: 11 }
   361                    - { _id: 2, x: 22 }
   362                    - { _id: 3, x: 33 }
   363                    - { _id: 4, x: 44 }
   364    -
   365        description: "BulkWrite continue-on-error behavior with unordered (duplicate key in requests)"
   366        operation:
   367            name: "bulkWrite"
   368            arguments:
   369                requests:
   370                    -
   371                        name: "insertOne"
   372                        arguments:
   373                            document: { _id: 3, x: 33 }
   374                    -
   375                        name: "insertOne"
   376                        arguments:
   377                            document: { _id: 3, x: 33 }
   378                    -
   379                        name: "insertOne"
   380                        arguments:
   381                            document: { _id: 4, x: 44 }
   382                options: { ordered: false }
   383        outcome:
   384            error: true
   385            result:
   386                deletedCount: 0
   387                insertedCount: 2
   388                # Since the map of insertedIds is generated before execution it
   389                # could indicate inserts that did not actually succeed. We omit
   390                # this field rather than expect drivers to provide an accurate
   391                # map filtered by write errors.
   392                matchedCount: 0
   393                modifiedCount: 0
   394                upsertedCount: 0
   395                upsertedIds: { }
   396            collection:
   397                data:
   398                    - { _id: 1, x: 11 }
   399                    - { _id: 2, x: 22 }
   400                    - { _id: 3, x: 33 }
   401                    - { _id: 4, x: 44 }

View as plain text