@@ -98,6 +98,7 @@ void describe('MongoDB Compatibility Tests', () => {
9898 } ,
9999 ) ;
100100 } ) ;
101+
101102 void it ( 'should insert many documents into both PostgreSQL and MongoDB' , async ( ) => {
102103 const pongoCollection = pongoDb . collection < User > ( 'insertMany' ) ;
103104 const mongoCollection = mongoDb . collection < User > ( 'insertMany' ) ;
@@ -162,14 +163,57 @@ void describe('MongoDB Compatibility Tests', () => {
162163 _id : mongoInsertResult . insertedId ,
163164 } ) ;
164165
166+ assert . equal ( mongoDoc ?. age , 31 ) ;
165167 assert . deepStrictEqual (
166168 {
167169 name : pongoDoc ! . name ,
168- age : 31 ,
170+ age : pongoDoc ! . age ,
169171 } ,
170172 {
171173 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 ,
173217 } ,
174218 ) ;
175219 } ) ;
@@ -218,11 +262,11 @@ void describe('MongoDB Compatibility Tests', () => {
218262 assert . deepStrictEqual (
219263 pongoDocs . map ( ( doc ) => ( {
220264 name : doc . name ,
221- age : 31 ,
265+ age : doc . age ,
222266 } ) ) ,
223267 mongoDocs . map ( ( doc ) => ( {
224268 name : doc . name ,
225- age : 31 ,
269+ age : doc . age ,
226270 } ) ) ,
227271 ) ;
228272 } ) ;
@@ -235,10 +279,11 @@ void describe('MongoDB Compatibility Tests', () => {
235279 const pongoInsertResult = await pongoCollection . insertOne ( doc ) ;
236280 const mongoInsertResult = await mongoCollection . insertOne ( doc ) ;
237281
238- await pongoCollection . updateOne (
282+ const { matchedCount } = await pongoCollection . updateOne (
239283 { _id : pongoInsertResult . insertedId } ,
240284 { $unset : { address : '' } } ,
241285 ) ;
286+ assert . equal ( matchedCount , 1 ) ;
242287 await mongoCollection . updateOne (
243288 { _id : mongoInsertResult . insertedId } ,
244289 { $unset : { address : '' } } ,
@@ -275,10 +320,11 @@ void describe('MongoDB Compatibility Tests', () => {
275320
276321 const update = { $inc : { age : 1 } } ;
277322
278- await pongoCollection . updateOne (
323+ const { matchedCount } = await pongoCollection . updateOne (
279324 { _id : pongoInsertResult . insertedId } ,
280325 update ,
281326 ) ;
327+ assert . equal ( matchedCount , 1 ) ;
282328 await mongoCollection . updateOne (
283329 { _id : mongoInsertResult . insertedId } ,
284330 update ,
@@ -306,21 +352,39 @@ void describe('MongoDB Compatibility Tests', () => {
306352 void it ( 'should update a document in both PostgreSQL and MongoDB using $push' , async ( ) => {
307353 const pongoCollection = pongoDb . collection < User > ( 'testCollection' ) ;
308354 const mongoCollection = mongoDb . collection < User > ( 'testCollection' ) ;
309- const doc = { name : 'Roger' , age : 30 , tags : [ 'tag1' ] } ;
355+ const doc = { name : 'Roger' , age : 30 } ;
310356
311357 const pongoInsertResult = await pongoCollection . insertOne ( doc ) ;
312358 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+ } ) ;
313375
314- await pongoCollection . updateOne (
376+ // Push to existing
377+ updateResult = await pongoCollection . updateOne (
315378 { _id : pongoInsertResult . insertedId } ,
316379 { $push : { tags : 'tag2' } } ,
317380 ) ;
381+ assert . equal ( updateResult . matchedCount , 1 ) ;
318382 await mongoCollection . updateOne (
319383 { _id : mongoInsertResult . insertedId } ,
320384 { $push : { tags : 'tag2' } } ,
321385 ) ;
322386
323- const pongoDoc = await pongoCollection . findOne ( {
387+ pongoDoc = await pongoCollection . findOne ( {
324388 _id : pongoInsertResult . insertedId ,
325389 } ) ;
326390 const mongoDoc = await mongoCollection . findOne ( {
@@ -351,7 +415,10 @@ void describe('MongoDB Compatibility Tests', () => {
351415 const pongoInsertResult = await pongoCollection . insertOne ( doc ) ;
352416 const mongoInsertResult = await mongoCollection . insertOne ( doc ) ;
353417
354- await pongoCollection . deleteOne ( { _id : pongoInsertResult . insertedId } ) ;
418+ const { deletedCount } = await pongoCollection . deleteOne ( {
419+ _id : pongoInsertResult . insertedId ,
420+ } ) ;
421+ assert . equal ( deletedCount , 1 ) ;
355422 await mongoCollection . deleteOne ( { _id : mongoInsertResult . insertedId } ) ;
356423
357424 const pongoDoc = await pongoCollection . findOne ( {
@@ -475,8 +542,12 @@ void describe('MongoDB Compatibility Tests', () => {
475542 } ) ;
476543
477544 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+ ) ;
480551
481552 const docs = [
482553 {
@@ -522,8 +593,12 @@ void describe('MongoDB Compatibility Tests', () => {
522593 } ) ;
523594
524595 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+ ) ;
527602
528603 const docs = [
529604 {
@@ -625,8 +700,8 @@ void describe('MongoDB Compatibility Tests', () => {
625700 } ) ;
626701
627702 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 ' ) ;
630705
631706 const docs = [
632707 { name : 'Anita' , age : 25 , tags : [ 'tag1' , 'tag2' ] } ,
@@ -652,8 +727,12 @@ void describe('MongoDB Compatibility Tests', () => {
652727 } ) ;
653728
654729 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+ ) ;
657736
658737 const docs = [
659738 { name : 'Anita' , age : 25 , tags : [ 'tag1' , 'tag2' ] } ,
@@ -714,8 +793,12 @@ void describe('MongoDB Compatibility Tests', () => {
714793 } ) ;
715794
716795 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+ ) ;
719802
720803 const docs = [
721804 {
0 commit comments