@@ -98,6 +98,7 @@ void describe('MongoDB Compatibility Tests', () => {
98
98
} ,
99
99
) ;
100
100
} ) ;
101
+
101
102
void it ( 'should insert many documents into both PostgreSQL and MongoDB' , async ( ) => {
102
103
const pongoCollection = pongoDb . collection < User > ( 'insertMany' ) ;
103
104
const mongoCollection = mongoDb . collection < User > ( 'insertMany' ) ;
@@ -162,14 +163,57 @@ void describe('MongoDB Compatibility Tests', () => {
162
163
_id : mongoInsertResult . insertedId ,
163
164
} ) ;
164
165
166
+ assert . equal ( mongoDoc ?. age , 31 ) ;
165
167
assert . deepStrictEqual (
166
168
{
167
169
name : pongoDoc ! . name ,
168
- age : 31 ,
170
+ age : pongoDoc ! . age ,
169
171
} ,
170
172
{
171
173
name : mongoDoc ! . name ,
172
- age : 31 ,
174
+ age : mongoDoc ! . age ,
175
+ } ,
176
+ ) ;
177
+ } ) ;
178
+
179
+ void it ( 'should update a multiple properties in document in both PostgreSQL and MongoDB' , async ( ) => {
180
+ const pongoCollection = pongoDb . collection < User > ( 'updateOneMultiple' ) ;
181
+ const mongoCollection = mongoDb . collection < User > ( 'updateOneMultiple' ) ;
182
+ const doc = { name : 'Roger' , age : 30 } ;
183
+
184
+ const pongoInsertResult = await pongoCollection . insertOne ( doc ) ;
185
+ const mongoInsertResult = await mongoCollection . insertOne ( doc ) ;
186
+
187
+ const update = { $set : { age : 31 , tags : [ ] } } ;
188
+
189
+ await pongoCollection . updateOne (
190
+ { _id : pongoInsertResult . insertedId } ,
191
+ update ,
192
+ ) ;
193
+ await mongoCollection . updateOne (
194
+ { _id : mongoInsertResult . insertedId } ,
195
+ update ,
196
+ ) ;
197
+
198
+ const pongoDoc = await pongoCollection . findOne ( {
199
+ _id : pongoInsertResult . insertedId ,
200
+ } ) ;
201
+ const mongoDoc = await mongoCollection . findOne ( {
202
+ _id : mongoInsertResult . insertedId ,
203
+ } ) ;
204
+
205
+ assert . equal ( mongoDoc ?. age , 31 ) ;
206
+ assert . deepEqual ( mongoDoc ?. tags , [ ] ) ;
207
+ assert . deepStrictEqual (
208
+ {
209
+ name : pongoDoc ! . name ,
210
+ age : pongoDoc ! . age ,
211
+ tags : pongoDoc ! . tags ,
212
+ } ,
213
+ {
214
+ name : mongoDoc ! . name ,
215
+ age : mongoDoc ! . age ,
216
+ tags : mongoDoc ! . tags ,
173
217
} ,
174
218
) ;
175
219
} ) ;
@@ -218,11 +262,11 @@ void describe('MongoDB Compatibility Tests', () => {
218
262
assert . deepStrictEqual (
219
263
pongoDocs . map ( ( doc ) => ( {
220
264
name : doc . name ,
221
- age : 31 ,
265
+ age : doc . age ,
222
266
} ) ) ,
223
267
mongoDocs . map ( ( doc ) => ( {
224
268
name : doc . name ,
225
- age : 31 ,
269
+ age : doc . age ,
226
270
} ) ) ,
227
271
) ;
228
272
} ) ;
@@ -235,10 +279,11 @@ void describe('MongoDB Compatibility Tests', () => {
235
279
const pongoInsertResult = await pongoCollection . insertOne ( doc ) ;
236
280
const mongoInsertResult = await mongoCollection . insertOne ( doc ) ;
237
281
238
- await pongoCollection . updateOne (
282
+ const { matchedCount } = await pongoCollection . updateOne (
239
283
{ _id : pongoInsertResult . insertedId } ,
240
284
{ $unset : { address : '' } } ,
241
285
) ;
286
+ assert . equal ( matchedCount , 1 ) ;
242
287
await mongoCollection . updateOne (
243
288
{ _id : mongoInsertResult . insertedId } ,
244
289
{ $unset : { address : '' } } ,
@@ -275,10 +320,11 @@ void describe('MongoDB Compatibility Tests', () => {
275
320
276
321
const update = { $inc : { age : 1 } } ;
277
322
278
- await pongoCollection . updateOne (
323
+ const { matchedCount } = await pongoCollection . updateOne (
279
324
{ _id : pongoInsertResult . insertedId } ,
280
325
update ,
281
326
) ;
327
+ assert . equal ( matchedCount , 1 ) ;
282
328
await mongoCollection . updateOne (
283
329
{ _id : mongoInsertResult . insertedId } ,
284
330
update ,
@@ -306,21 +352,39 @@ void describe('MongoDB Compatibility Tests', () => {
306
352
void it ( 'should update a document in both PostgreSQL and MongoDB using $push' , async ( ) => {
307
353
const pongoCollection = pongoDb . collection < User > ( 'testCollection' ) ;
308
354
const mongoCollection = mongoDb . collection < User > ( 'testCollection' ) ;
309
- const doc = { name : 'Roger' , age : 30 , tags : [ 'tag1' ] } ;
355
+ const doc = { name : 'Roger' , age : 30 } ;
310
356
311
357
const pongoInsertResult = await pongoCollection . insertOne ( doc ) ;
312
358
const mongoInsertResult = await mongoCollection . insertOne ( doc ) ;
359
+ let pongoDoc = await pongoCollection . findOne ( {
360
+ _id : pongoInsertResult . insertedId ,
361
+ } ) ;
362
+ // Push to non existing
363
+ let updateResult = await pongoCollection . updateOne (
364
+ { _id : pongoInsertResult . insertedId } ,
365
+ { $push : { tags : 'tag1' } } ,
366
+ ) ;
367
+ assert . equal ( updateResult . matchedCount , 1 ) ;
368
+ await mongoCollection . updateOne (
369
+ { _id : mongoInsertResult . insertedId } ,
370
+ { $push : { tags : 'tag1' } } ,
371
+ ) ;
372
+ pongoDoc = await pongoCollection . findOne ( {
373
+ _id : pongoInsertResult . insertedId ,
374
+ } ) ;
313
375
314
- await pongoCollection . updateOne (
376
+ // Push to existing
377
+ updateResult = await pongoCollection . updateOne (
315
378
{ _id : pongoInsertResult . insertedId } ,
316
379
{ $push : { tags : 'tag2' } } ,
317
380
) ;
381
+ assert . equal ( updateResult . matchedCount , 1 ) ;
318
382
await mongoCollection . updateOne (
319
383
{ _id : mongoInsertResult . insertedId } ,
320
384
{ $push : { tags : 'tag2' } } ,
321
385
) ;
322
386
323
- const pongoDoc = await pongoCollection . findOne ( {
387
+ pongoDoc = await pongoCollection . findOne ( {
324
388
_id : pongoInsertResult . insertedId ,
325
389
} ) ;
326
390
const mongoDoc = await mongoCollection . findOne ( {
@@ -351,7 +415,10 @@ void describe('MongoDB Compatibility Tests', () => {
351
415
const pongoInsertResult = await pongoCollection . insertOne ( doc ) ;
352
416
const mongoInsertResult = await mongoCollection . insertOne ( doc ) ;
353
417
354
- await pongoCollection . deleteOne ( { _id : pongoInsertResult . insertedId } ) ;
418
+ const { deletedCount } = await pongoCollection . deleteOne ( {
419
+ _id : pongoInsertResult . insertedId ,
420
+ } ) ;
421
+ assert . equal ( deletedCount , 1 ) ;
355
422
await mongoCollection . deleteOne ( { _id : mongoInsertResult . insertedId } ) ;
356
423
357
424
const pongoDoc = await pongoCollection . findOne ( {
@@ -475,8 +542,12 @@ void describe('MongoDB Compatibility Tests', () => {
475
542
} ) ;
476
543
477
544
void it ( 'should find documents with a nested property filter in both PostgreSQL and MongoDB' , async ( ) => {
478
- const pongoCollection = pongoDb . collection < User > ( 'testCollection' ) ;
479
- const mongoCollection = mongoDb . collection < User > ( 'testCollection' ) ;
545
+ const pongoCollection = pongoDb . collection < User > (
546
+ 'findWithNestedProperty' ,
547
+ ) ;
548
+ const mongoCollection = mongoDb . collection < User > (
549
+ 'findWithNestedProperty' ,
550
+ ) ;
480
551
481
552
const docs = [
482
553
{
@@ -522,8 +593,12 @@ void describe('MongoDB Compatibility Tests', () => {
522
593
} ) ;
523
594
524
595
void it ( 'should find documents with multiple nested property filters in both PostgreSQL and MongoDB' , async ( ) => {
525
- const pongoCollection = pongoDb . collection < User > ( 'testCollection' ) ;
526
- const mongoCollection = mongoDb . collection < User > ( 'testCollection' ) ;
596
+ const pongoCollection = pongoDb . collection < User > (
597
+ 'findWithMultipleNestedProperties' ,
598
+ ) ;
599
+ const mongoCollection = mongoDb . collection < User > (
600
+ 'findWithMultipleNestedProperties' ,
601
+ ) ;
527
602
528
603
const docs = [
529
604
{
@@ -625,8 +700,8 @@ void describe('MongoDB Compatibility Tests', () => {
625
700
} ) ;
626
701
627
702
void it ( 'should find documents with an array filter in both PostgreSQL and MongoDB' , async ( ) => {
628
- const pongoCollection = pongoDb . collection < User > ( 'testCollection ' ) ;
629
- const mongoCollection = mongoDb . collection < User > ( 'testCollection ' ) ;
703
+ const pongoCollection = pongoDb . collection < User > ( 'findWithArrayFilter ' ) ;
704
+ const mongoCollection = mongoDb . collection < User > ( 'findWithArrayFilter ' ) ;
630
705
631
706
const docs = [
632
707
{ name : 'Anita' , age : 25 , tags : [ 'tag1' , 'tag2' ] } ,
@@ -652,8 +727,12 @@ void describe('MongoDB Compatibility Tests', () => {
652
727
} ) ;
653
728
654
729
void it ( 'should find documents with multiple array filters in both PostgreSQL and MongoDB' , async ( ) => {
655
- const pongoCollection = pongoDb . collection < User > ( 'testCollection' ) ;
656
- const mongoCollection = mongoDb . collection < User > ( 'testCollection' ) ;
730
+ const pongoCollection = pongoDb . collection < User > (
731
+ 'findWithMultipleArrayFilters' ,
732
+ ) ;
733
+ const mongoCollection = mongoDb . collection < User > (
734
+ 'findWithMultipleArrayFilters' ,
735
+ ) ;
657
736
658
737
const docs = [
659
738
{ name : 'Anita' , age : 25 , tags : [ 'tag1' , 'tag2' ] } ,
@@ -714,8 +793,12 @@ void describe('MongoDB Compatibility Tests', () => {
714
793
} ) ;
715
794
716
795
void it ( 'should find documents with a nested array element match filter in both PostgreSQL and MongoDB' , async ( ) => {
717
- const pongoCollection = pongoDb . collection < User > ( 'testCollection' ) ;
718
- const mongoCollection = mongoDb . collection < User > ( 'testCollection' ) ;
796
+ const pongoCollection = pongoDb . collection < User > (
797
+ 'findWithElemMatchFilter' ,
798
+ ) ;
799
+ const mongoCollection = mongoDb . collection < User > (
800
+ 'findWithElemMatchFilter' ,
801
+ ) ;
719
802
720
803
const docs = [
721
804
{
0 commit comments