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