1description: "poc-crud"
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  - database:
14      id: &database1 database1
15      client: *client0
16      databaseName: &database1Name admin
17  - collection:
18      id: &collection0 collection0
19      database: *database0
20      collectionName: &collection0Name coll0
21  - collection:
22      id: &collection1 collection1
23      database: *database0
24      collectionName: &collection1Name coll1
25  - collection:
26      id: &collection2 collection2
27      database: *database0
28      collectionName: &collection2Name coll2
29      collectionOptions:
30        readConcern: { level: majority }
31
32initialData:
33  - collectionName: *collection0Name
34    databaseName: *database0Name
35    documents:
36      - { _id: 1, x: 11 }
37      - { _id: 2, x: 22 }
38  - collectionName: *collection1Name
39    databaseName: *database0Name
40    documents:
41      - { _id: 1, x: 11 }
42  - collectionName: *collection2Name
43    databaseName: *database0Name
44    documents:
45      - { _id: 1, x: 11 }
46      - { _id: 2, x: 22 }
47      - { _id: 3, x: 33 }
48  - collectionName: &out aggregate_out
49    databaseName: *database0Name
50    documents: []
51
52tests:
53  - description: "BulkWrite with mixed ordered operations"
54    operations:
55      - name: bulkWrite
56        object: *collection0
57        arguments:
58          requests:
59            - insertOne:
60                document: { _id: 3, x: 33 }
61            - updateOne:
62                filter: { _id: 2 }
63                update: { $inc: { x: 1 } }
64            - updateMany:
65                filter: { _id: { $gt: 1 } }
66                update: { $inc: { x: 1 } }
67            - insertOne:
68                document: { _id: 4, x: 44 }
69            - deleteMany:
70                filter: { x: { $nin: [ 24, 34 ] } }
71            - replaceOne:
72                filter: { _id: 4 }
73                replacement: { _id: 4, x: 44 }
74                upsert: true
75          ordered: true
76        expectResult:
77          deletedCount: 2
78          insertedCount: 2
79          insertedIds: { $$unsetOrMatches: { 0: 3, 3: 4 } }
80          matchedCount: 3
81          modifiedCount: 3
82          upsertedCount: 1
83          upsertedIds: { 5: 4 }
84    outcome:
85      - collectionName: *collection0Name
86        databaseName: *database0Name
87        documents:
88          - {_id: 2, x: 24 }
89          - {_id: 3, x: 34 }
90          - {_id: 4, x: 44 }
91
92  - description: "InsertMany continue-on-error behavior with unordered (duplicate key in requests)"
93    operations:
94      - name: insertMany
95        object: *collection1
96        arguments:
97          documents:
98            - { _id: 2, x: 22 }
99            - { _id: 2, x: 22 }
100            - { _id: 3, x: 33 }
101          ordered: false
102        expectError:
103          expectResult:
104            deletedCount: 0
105            insertedCount: 2
106            # Since the map of insertedIds is generated before execution it
107            # could indicate inserts that did not actually succeed. We omit
108            # this field rather than expect drivers to provide an accurate
109            # map filtered by write errors.
110            matchedCount: 0
111            modifiedCount: 0
112            upsertedCount: 0
113            upsertedIds: { }
114    outcome:
115      - collectionName: *collection1Name
116        databaseName: *database0Name
117        documents:
118          - { _id: 1, x: 11 }
119          - { _id: 2, x: 22 }
120          - { _id: 3, x: 33 }
121
122  - description: "ReplaceOne prohibits atomic modifiers"
123    operations:
124      - name: replaceOne
125        object: *collection1
126        arguments:
127          filter: { _id: 1 }
128          replacement: { $set: { x: 22 }}
129        expectError:
130          isClientError: true
131    expectEvents:
132      - client: *client0
133        events: []
134    outcome:
135      - collectionName: *collection1Name
136        databaseName: *database0Name
137        documents:
138          - { _id: 1, x: 11 }
139
140  - description: "readConcern majority with out stage"
141    runOnRequirements:
142      - minServerVersion: "4.1.0"
143        topologies: [ replicaset, sharded-replicaset ]
144    operations:
145      - name: aggregate
146        object: *collection2
147        arguments:
148          pipeline: &pipeline
149            - $sort: { x : 1 }
150            - $match: { _id: { $gt: 1 } }
151            - $out: *out
152    expectEvents:
153      - client: *client0
154        events:
155          - commandStartedEvent:
156              command:
157                aggregate: *collection2Name
158                pipeline: *pipeline
159                readConcern: { level: majority }
160              # The following two assertions were not in the original test
161              commandName: aggregate
162              databaseName: *database0Name
163    outcome:
164      - collectionName: *out
165        databaseName: *database0Name
166        documents:
167          - { _id: 2, x: 22 }
168          - { _id: 3, x: 33 }
169
170  - description: "Aggregate with $listLocalSessions"
171    runOnRequirements:
172      - minServerVersion: "3.6.0"
173    operations:
174      - name: aggregate
175        object: *database1
176        arguments:
177          pipeline:
178            - $listLocalSessions: { }
179            - $limit: 1
180            - $addFields: { dummy: "dummy field"}
181            - $project: { _id: 0, dummy: 1}
182        expectResult:
183          - { dummy: "dummy field" }
184