...

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

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

     1data:
     2    - {_id: 1, x: 11}
     3    - {_id: 2, x: 22}
     4    - {_id: 3, x: 33}
     5minServerVersion: '2.6'
     6
     7tests:
     8    -
     9        description: "UpdateMany when many documents match"
    10        operation:
    11            name: "updateMany"
    12            arguments:
    13                filter: 
    14                    _id: {$gt: 1}
    15                update: 
    16                    $inc: {x: 1}
    17
    18        outcome:
    19            result:
    20                matchedCount: 2
    21                modifiedCount: 2
    22                upsertedCount: 0
    23            collection:
    24                data:
    25                    - {_id: 1, x: 11}
    26                    - {_id: 2, x: 23}
    27                    - {_id: 3, x: 34}
    28    -
    29        description: "UpdateMany when one document matches"
    30        operation:
    31            name: "updateMany"
    32            arguments:
    33                filter: {_id: 1}
    34                update: 
    35                    $inc: {x: 1}
    36
    37        outcome:
    38            result:
    39                matchedCount: 1
    40                modifiedCount: 1
    41                upsertedCount: 0
    42            collection:
    43                data:
    44                    - {_id: 1, x: 12}
    45                    - {_id: 2, x: 22}
    46                    - {_id: 3, x: 33}
    47    -
    48        description: "UpdateMany when no documents match"
    49        operation:
    50            name: "updateMany"
    51            arguments:
    52                filter: {_id: 4}
    53                update: 
    54                    $inc: {x: 1}
    55
    56        outcome:
    57            result:
    58                matchedCount: 0
    59                modifiedCount: 0
    60                upsertedCount: 0
    61            collection:
    62                data:
    63                    - {_id: 1, x: 11}
    64                    - {_id: 2, x: 22}
    65                    - {_id: 3, x: 33}
    66    -
    67        description: "UpdateMany with upsert when no documents match"
    68        operation:
    69            name: "updateMany"
    70            arguments:
    71                filter: {_id: 4}
    72                update: 
    73                    $inc: {x: 1}
    74                upsert: true
    75
    76        outcome:
    77            result:
    78                matchedCount: 0
    79                modifiedCount: 0
    80                upsertedCount: 1
    81                upsertedId: 4
    82            collection:
    83                data:
    84                    - {_id: 1, x: 11}
    85                    - {_id: 2, x: 22}
    86                    - {_id: 3, x: 33}
    87                    - {_id: 4, x: 1}

View as plain text