...

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

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

     1description: "insertOne-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  - collection:
    18      id: &collection1 collection1
    19      database: *database0
    20      collectionName: &collection1Name coll1
    21      collectionOptions:
    22        writeConcern: { w: 0 }
    23
    24initialData: &initialData
    25  - collectionName: *collection0Name
    26    databaseName: *database0Name
    27    documents: []
    28
    29tests:
    30  - description: "Inserting document with top-level dollar-prefixed key on 5.0+ server"
    31    runOnRequirements:
    32      - minServerVersion: "5.0"
    33    operations:
    34      - name: insertOne
    35        object: *collection0
    36        arguments:
    37          document: &dollarPrefixedKey { _id: 1, $a: 1 }
    38        expectResult: &insertResult
    39          # InsertOneResult is optional because all of its fields are optional
    40          $$unsetOrMatches: { insertedId: { $$unsetOrMatches: 1 } }
    41    expectEvents: &expectEventsDollarPrefixedKey
    42      - client: *client0
    43        events:
    44          - commandStartedEvent:
    45              command:
    46                insert: *collection0Name
    47                documents:
    48                  - *dollarPrefixedKey
    49    outcome:
    50      - collectionName: *collection0Name
    51        databaseName: *database0Name
    52        documents:
    53          - *dollarPrefixedKey
    54
    55  - description: "Inserting document with top-level dollar-prefixed key on pre-5.0 server yields server-side error"
    56    runOnRequirements:
    57      - maxServerVersion: "4.99"
    58    operations:
    59      - name: insertOne
    60        object: *collection0
    61        arguments:
    62          document: *dollarPrefixedKey
    63        expectError:
    64          isClientError: false
    65    expectEvents: *expectEventsDollarPrefixedKey
    66    outcome: *initialData
    67
    68  - description: "Inserting document with top-level dotted key"
    69    operations:
    70      - name: insertOne
    71        object: *collection0
    72        arguments:
    73          document: &dottedKey { _id: 1, a.b: 1 }
    74        expectResult: *insertResult
    75    expectEvents:
    76      - client: *client0
    77        events:
    78          - commandStartedEvent:
    79              command:
    80                insert: *collection0Name
    81                documents:
    82                  - *dottedKey
    83    outcome:
    84      - collectionName: *collection0Name
    85        databaseName: *database0Name
    86        documents:
    87          - *dottedKey
    88
    89  - description: "Inserting document with dollar-prefixed key in embedded doc"
    90    operations:
    91      - name: insertOne
    92        object: *collection0
    93        arguments:
    94          document: &dollarPrefixedKeyInEmbedded { _id: 1, a: { $b: 1 } }
    95        expectResult: *insertResult
    96    expectEvents:
    97      - client: *client0
    98        events:
    99          - commandStartedEvent:
   100              command:
   101                insert: *collection0Name
   102                documents:
   103                  - *dollarPrefixedKeyInEmbedded
   104    outcome:
   105      - collectionName: *collection0Name
   106        databaseName: *database0Name
   107        documents:
   108          - *dollarPrefixedKeyInEmbedded
   109
   110  - description: "Inserting document with dotted key in embedded doc"
   111    operations:
   112      - name: insertOne
   113        object: *collection0
   114        arguments:
   115          document: &dottedKeyInEmbedded { _id: 1, a: { b.c: 1 } }
   116        expectResult: *insertResult
   117    expectEvents:
   118      - client: *client0
   119        events:
   120          - commandStartedEvent:
   121              command:
   122                insert: *collection0Name
   123                documents:
   124                  - *dottedKeyInEmbedded
   125    outcome:
   126      - collectionName: *collection0Name
   127        databaseName: *database0Name
   128        documents:
   129          - *dottedKeyInEmbedded
   130
   131  - description: "Inserting document with dollar-prefixed key in _id yields server-side error"
   132    # Note: 5.0+ did not remove restrictions on dollar-prefixed keys in _id documents
   133    operations:
   134      - name: insertOne
   135        object: *collection0
   136        arguments:
   137          document: &dollarPrefixedKeyInId { _id: { $a: 1 } }
   138        expectError:
   139          isClientError: false
   140    expectEvents:
   141      - client: *client0
   142        events:
   143          - commandStartedEvent:
   144              command:
   145                insert: *collection0Name
   146                documents:
   147                  - *dollarPrefixedKeyInId
   148    outcome: *initialData
   149
   150  - description: "Inserting document with dotted key in _id on 3.6+ server"
   151    runOnRequirements:
   152      - minServerVersion: "3.6"
   153    operations:
   154      - name: insertOne
   155        object: *collection0
   156        arguments:
   157          document: &dottedKeyInId { _id: { a.b: 1 } }
   158        expectResult:
   159          # InsertOneResult is optional because all of its fields are optional
   160          $$unsetOrMatches: { insertedId: { $$unsetOrMatches: { a.b: 1 } } }
   161    expectEvents: &expectEventsDottedKeyInId
   162      - client: *client0
   163        events:
   164          - commandStartedEvent:
   165              command:
   166                insert: *collection0Name
   167                documents:
   168                  - *dottedKeyInId
   169    outcome:
   170      - collectionName: *collection0Name
   171        databaseName: *database0Name
   172        documents:
   173          - *dottedKeyInId
   174
   175  - description: "Inserting document with dotted key in _id on pre-3.6 server yields server-side error"
   176    runOnRequirements:
   177      - maxServerVersion: "3.4.99"
   178    operations:
   179      - name: insertOne
   180        object: *collection0
   181        arguments:
   182          document: *dottedKeyInId
   183        expectError:
   184          isClientError: false
   185    expectEvents: *expectEventsDottedKeyInId
   186    outcome: *initialData
   187
   188  - description: "Inserting document with DBRef-like keys"
   189    operations:
   190      - name: insertOne
   191        object: *collection0
   192        arguments:
   193          # Note: an incomplete DBRef document may cause issues loading the test
   194          # file with an Extended JSON parser, since the presence of one DBRef
   195          # key may cause the parser to require others and/or enforce expected
   196          # types (e.g. $ref and $db must be strings).
   197          #
   198          # Using "$db" here works for libmongoc so long as it's a string type;
   199          # however, neither $ref nor $id would be accepted on their own.
   200          #
   201          # See https://github.com/mongodb/specifications/blob/master/source/extended-json.rst#parsers
   202          document: &dbrefLikeKey { _id: 1, a: { $db: "foo" } }
   203        expectResult: *insertResult
   204    expectEvents:
   205      - client: *client0
   206        events:
   207          - commandStartedEvent:
   208              command:
   209                insert: *collection0Name
   210                documents:
   211                  - *dbrefLikeKey
   212    outcome:
   213      - collectionName: *collection0Name
   214        databaseName: *database0Name
   215        documents:
   216          - *dbrefLikeKey
   217
   218  - description: "Unacknowledged write using dollar-prefixed or dotted keys may be silently rejected on pre-5.0 server"
   219    runOnRequirements:
   220      - maxServerVersion: "4.99"
   221    operations:
   222      - name: insertOne
   223        object: *collection1
   224        arguments:
   225          document: *dollarPrefixedKeyInId
   226        expectResult:
   227          # InsertOneResult is optional because all of its fields are optional
   228          $$unsetOrMatches: { acknowledged: { $$unsetOrMatches: false } }
   229    expectEvents:
   230      - client: *client0
   231        events:
   232          - commandStartedEvent:
   233              command:
   234                insert: *collection1Name
   235                documents:
   236                  - *dollarPrefixedKeyInId
   237                writeConcern: { w: 0 }
   238    outcome: *initialData

View as plain text