...

Text file src/go.mongodb.org/mongo-driver/testdata/crud/unified/bulkWrite-updateMany-dots_and_dollars.yml

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

     1description: "bulkWrite-updateMany-dots_and_dollars"
     2
     3schemaVersion: "1.0"
     4
     5createEntities:
     6  - client:
     7      id: &client0 client0
     8      observeEvents: [ commandStartedEvent ]
     9  - database:
    10      id: &database0 database0
    11      client: *client0
    12      databaseName: &database0Name crud-tests
    13  - collection:
    14      id: &collection0 collection0
    15      database: *database0
    16      collectionName: &collection0Name coll0
    17
    18initialData: &initialData
    19  - collectionName: *collection0Name
    20    databaseName: *database0Name
    21    documents:
    22      - { _id: 1, foo: {} }
    23
    24tests:
    25  - description: "Updating document to set top-level dollar-prefixed key on 5.0+ server"
    26    runOnRequirements:
    27      - minServerVersion: "5.0"
    28    operations:
    29      - name: bulkWrite
    30        object: *collection0
    31        arguments:
    32          requests:
    33            - updateMany:
    34                filter: { _id: 1 }
    35                update: &dollarPrefixedKey
    36                  - { $replaceWith: { $setField: { field: { $literal: $a }, value: 1, input: $$ROOT } } }
    37        expectResult: &bulkWriteResult
    38          deletedCount: 0
    39          insertedCount: 0
    40          insertedIds: { $$unsetOrMatches: { } }
    41          matchedCount: 1
    42          modifiedCount: 1
    43          upsertedCount: 0
    44          upsertedIds: { }
    45    expectEvents:
    46      - client: *client0
    47        events:
    48          - commandStartedEvent:
    49              command:
    50                update: *collection0Name
    51                updates:
    52                  - q: { _id: 1 }
    53                    u: *dollarPrefixedKey
    54                    multi: true
    55                    upsert: { $$unsetOrMatches: false }
    56    outcome:
    57      - collectionName: *collection0Name
    58        databaseName: *database0Name
    59        documents:
    60          - { _id: 1, foo: {}, $a: 1 }
    61
    62  - description: "Updating document to set top-level dotted key on 5.0+ server"
    63    runOnRequirements:
    64      - minServerVersion: "5.0"
    65    operations:
    66      - name: bulkWrite
    67        object: *collection0
    68        arguments:
    69          requests:
    70            - updateMany:
    71                filter: { _id: 1 }
    72                update: &dottedKey
    73                  - { $replaceWith: { $setField: { field: { $literal: a.b }, value: 1, input: $$ROOT } } }
    74        expectResult: *bulkWriteResult
    75    expectEvents:
    76      - client: *client0
    77        events:
    78          - commandStartedEvent:
    79              command:
    80                update: *collection0Name
    81                updates:
    82                  - q: { _id: 1 }
    83                    u: *dottedKey
    84                    multi: true
    85                    upsert: { $$unsetOrMatches: false }
    86    outcome:
    87      - collectionName: *collection0Name
    88        databaseName: *database0Name
    89        documents:
    90          - { _id: 1, foo: {}, a.b: 1 }
    91
    92  - description: "Updating document to set dollar-prefixed key in embedded doc on 5.0+ server"
    93    runOnRequirements:
    94      - minServerVersion: "5.0"
    95    operations:
    96      - name: bulkWrite
    97        object: *collection0
    98        arguments:
    99          requests:
   100            - updateMany:
   101                filter: { _id: 1 }
   102                update: &dollarPrefixedKeyInEmbedded
   103                  - { $set: { foo: { $setField: { field: { $literal: $a }, value: 1, input: $foo } } } }
   104        expectResult: *bulkWriteResult
   105    expectEvents:
   106      - client: *client0
   107        events:
   108          - commandStartedEvent:
   109              command:
   110                update: *collection0Name
   111                updates:
   112                  - q: { _id: 1 }
   113                    u: *dollarPrefixedKeyInEmbedded
   114                    multi: true
   115                    upsert: { $$unsetOrMatches: false }
   116    outcome:
   117      - collectionName: *collection0Name
   118        databaseName: *database0Name
   119        documents:
   120          - { _id: 1, foo: { $a: 1 } }
   121
   122  - description: "Updating document to set dotted key in embedded doc on 5.0+ server"
   123    runOnRequirements:
   124      - minServerVersion: "5.0"
   125    operations:
   126      - name: bulkWrite
   127        object: *collection0
   128        arguments:
   129          requests:
   130            - updateMany:
   131                filter: { _id: 1 }
   132                update: &dottedKeyInEmbedded
   133                  - { $set: { foo: { $setField: { field: { $literal: a.b }, value: 1, input: $foo } } } }
   134        expectResult: *bulkWriteResult
   135    expectEvents:
   136      - client: *client0
   137        events:
   138          - commandStartedEvent:
   139              command:
   140                update: *collection0Name
   141                updates:
   142                  - q: { _id: 1 }
   143                    u: *dottedKeyInEmbedded
   144                    multi: true
   145                    upsert: { $$unsetOrMatches: false }
   146    outcome:
   147      - collectionName: *collection0Name
   148        databaseName: *database0Name
   149        documents:
   150          - { _id: 1, foo: { a.b: 1 } }

View as plain text