@@ -167,6 +167,120 @@ void describe('MongoDB Compatibility Tests', () => {
167
167
assert . strictEqual ( pongoDoc , null ) ;
168
168
assert . strictEqual ( mongoDoc , null ) ;
169
169
} ) ;
170
+
171
+ void it ( 'should update a document in both PostgreSQL and MongoDB using $unset' , async ( ) => {
172
+ const pongoCollection = pongoDb . collection < User > ( 'testCollection' ) ;
173
+ const mongoCollection = mongoDb . collection < User > ( 'testCollection' ) ;
174
+ const doc = { name : 'Roger' , age : 30 , address : { city : 'Wonderland' } } ;
175
+
176
+ const pongoInsertResult = await pongoCollection . insertOne ( doc ) ;
177
+ const mongoInsertResult = await mongoCollection . insertOne ( doc ) ;
178
+
179
+ await pongoCollection . updateOne (
180
+ { _id : pongoInsertResult . insertedId } ,
181
+ { $unset : { address : '' } } ,
182
+ ) ;
183
+ await mongoCollection . updateOne (
184
+ { _id : mongoInsertResult . insertedId } ,
185
+ { $unset : { address : '' } } ,
186
+ ) ;
187
+
188
+ const pongoDoc = await pongoCollection . findOne ( {
189
+ _id : pongoInsertResult . insertedId ,
190
+ } ) ;
191
+ const mongoDoc = await mongoCollection . findOne ( {
192
+ _id : mongoInsertResult . insertedId ,
193
+ } ) ;
194
+
195
+ assert . deepStrictEqual (
196
+ {
197
+ name : pongoDoc ! . name ,
198
+ age : pongoDoc ! . age ,
199
+ address : undefined ,
200
+ } ,
201
+ {
202
+ name : mongoDoc ! . name ,
203
+ age : mongoDoc ! . age ,
204
+ address : undefined ,
205
+ } ,
206
+ ) ;
207
+ } ) ;
208
+
209
+ void it ( 'should update a document in both PostgreSQL and MongoDB using $inc' , async ( ) => {
210
+ const pongoCollection = pongoDb . collection < User > ( 'testCollection' ) ;
211
+ const mongoCollection = mongoDb . collection < User > ( 'testCollection' ) ;
212
+ const doc = { name : 'Roger' , age : 30 } ;
213
+
214
+ const pongoInsertResult = await pongoCollection . insertOne ( doc ) ;
215
+ const mongoInsertResult = await mongoCollection . insertOne ( doc ) ;
216
+
217
+ const update = { $inc : { age : 1 } } ;
218
+
219
+ await pongoCollection . updateOne (
220
+ { _id : pongoInsertResult . insertedId } ,
221
+ update ,
222
+ ) ;
223
+ await mongoCollection . updateOne (
224
+ { _id : mongoInsertResult . insertedId } ,
225
+ update ,
226
+ ) ;
227
+
228
+ const pongoDoc = await pongoCollection . findOne ( {
229
+ _id : pongoInsertResult . insertedId ,
230
+ } ) ;
231
+ const mongoDoc = await mongoCollection . findOne ( {
232
+ _id : mongoInsertResult . insertedId ,
233
+ } ) ;
234
+
235
+ assert . deepStrictEqual (
236
+ {
237
+ name : pongoDoc ! . name ,
238
+ age : 31 ,
239
+ } ,
240
+ {
241
+ name : mongoDoc ! . name ,
242
+ age : 31 ,
243
+ } ,
244
+ ) ;
245
+ } ) ;
246
+
247
+ void it ( 'should update a document in both PostgreSQL and MongoDB using $push' , async ( ) => {
248
+ const pongoCollection = pongoDb . collection < User > ( 'testCollection' ) ;
249
+ const mongoCollection = mongoDb . collection < User > ( 'testCollection' ) ;
250
+ const doc = { name : 'Roger' , age : 30 , tags : [ 'tag1' ] } ;
251
+
252
+ const pongoInsertResult = await pongoCollection . insertOne ( doc ) ;
253
+ const mongoInsertResult = await mongoCollection . insertOne ( doc ) ;
254
+
255
+ await pongoCollection . updateOne (
256
+ { _id : pongoInsertResult . insertedId } ,
257
+ { $push : { tags : 'tag2' } } ,
258
+ ) ;
259
+ await mongoCollection . updateOne (
260
+ { _id : mongoInsertResult . insertedId } ,
261
+ { $push : { tags : 'tag2' } } ,
262
+ ) ;
263
+
264
+ const pongoDoc = await pongoCollection . findOne ( {
265
+ _id : pongoInsertResult . insertedId ,
266
+ } ) ;
267
+ const mongoDoc = await mongoCollection . findOne ( {
268
+ _id : mongoInsertResult . insertedId ,
269
+ } ) ;
270
+
271
+ assert . deepStrictEqual (
272
+ {
273
+ name : pongoDoc ! . name ,
274
+ age : pongoDoc ! . age ,
275
+ tags : [ 'tag1' , 'tag2' ] ,
276
+ } ,
277
+ {
278
+ name : mongoDoc ! . name ,
279
+ age : mongoDoc ! . age ,
280
+ tags : [ 'tag1' , 'tag2' ] ,
281
+ } ,
282
+ ) ;
283
+ } ) ;
170
284
} ) ;
171
285
172
286
void describe ( 'Find Operations' , ( ) => {
0 commit comments