...

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

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

     1description: "updateOne-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: updateOne
    30        object: *collection0
    31        arguments:
    32          filter: { _id: 1 }
    33          update: &dollarPrefixedKey
    34            - { $replaceWith: { $setField: { field: { $literal: $a }, value: 1, input: $$ROOT } } }
    35        expectResult: &updateResult
    36          matchedCount: 1
    37          modifiedCount: 1
    38          upsertedCount: 0
    39    expectEvents:
    40      - client: *client0
    41        events:
    42          - commandStartedEvent:
    43              command:
    44                update: *collection0Name
    45                updates:
    46                  - q: { _id: 1 }
    47                    u: *dollarPrefixedKey
    48                    multi: { $$unsetOrMatches: false }
    49                    upsert: { $$unsetOrMatches: false }
    50    outcome:
    51      - collectionName: *collection0Name
    52        databaseName: *database0Name
    53        documents:
    54          - { _id: 1, foo: {}, $a: 1 }
    55
    56  - description: "Updating document to set top-level dotted key on 5.0+ server"
    57    runOnRequirements:
    58      - minServerVersion: "5.0"
    59    operations:
    60      - name: updateOne
    61        object: *collection0
    62        arguments:
    63          filter: { _id: 1 }
    64          update: &dottedKey
    65            - { $replaceWith: { $setField: { field: { $literal: a.b }, value: 1, input: $$ROOT } } }
    66        expectResult: *updateResult
    67    expectEvents:
    68      - client: *client0
    69        events:
    70          - commandStartedEvent:
    71              command:
    72                update: *collection0Name
    73                updates:
    74                  - q: { _id: 1 }
    75                    u: *dottedKey
    76                    multi: { $$unsetOrMatches: false }
    77                    upsert: { $$unsetOrMatches: false }
    78    outcome:
    79      - collectionName: *collection0Name
    80        databaseName: *database0Name
    81        documents:
    82          - { _id: 1, foo: {}, a.b: 1 }
    83
    84  - description: "Updating document to set dollar-prefixed key in embedded doc on 5.0+ server"
    85    runOnRequirements:
    86      - minServerVersion: "5.0"
    87    operations:
    88      - name: updateOne
    89        object: *collection0
    90        arguments:
    91          filter: { _id: 1 }
    92          update: &dollarPrefixedKeyInEmbedded
    93            - { $set: { foo: { $setField: { field: { $literal: $a }, value: 1, input: $foo } } } }
    94        expectResult: *updateResult
    95    expectEvents:
    96      - client: *client0
    97        events:
    98          - commandStartedEvent:
    99              command:
   100                update: *collection0Name
   101                updates:
   102                  - q: { _id: 1 }
   103                    u: *dollarPrefixedKeyInEmbedded
   104                    multi: { $$unsetOrMatches: false }
   105                    upsert: { $$unsetOrMatches: false }
   106    outcome:
   107      - collectionName: *collection0Name
   108        databaseName: *database0Name
   109        documents:
   110          - { _id: 1, foo: { $a: 1 } }
   111
   112  - description: "Updating document to set dotted key in embedded doc on 5.0+ server"
   113    runOnRequirements:
   114      - minServerVersion: "5.0"
   115    operations:
   116      - name: updateOne
   117        object: *collection0
   118        arguments:
   119          filter: { _id: 1 }
   120          update: &dottedKeyInEmbedded
   121            - { $set: { foo: { $setField: { field: { $literal: a.b }, value: 1, input: $foo } } } }
   122        expectResult: *updateResult
   123    expectEvents:
   124      - client: *client0
   125        events:
   126          - commandStartedEvent:
   127              command:
   128                update: *collection0Name
   129                updates:
   130                  - q: { _id: 1 }
   131                    u: *dottedKeyInEmbedded
   132                    multi: { $$unsetOrMatches: false }
   133                    upsert: { $$unsetOrMatches: false }
   134    outcome:
   135      - collectionName: *collection0Name
   136        databaseName: *database0Name
   137        documents:
   138          - { _id: 1, foo: { a.b: 1 } }

View as plain text