@@ -315,33 +315,34 @@ describe('CRUD API', function () {
315
315
await db . collection ( 't1' ) . drop ( ) ;
316
316
} ) ;
317
317
318
- it ( 'allMethods' , async function ( ) {
319
- const cursor = db . collection ( 't1' ) . aggregate ( [ { $match : { } } ] , {
320
- allowDiskUse : true ,
321
- batchSize : 2 ,
322
- maxTimeMS : 50
323
- } ) ;
324
-
325
- // Exercise all the options
326
- cursor
327
- . geoNear ( { geo : 1 } )
328
- . group ( { group : 1 } )
329
- . limit ( 10 )
330
- . match ( { match : 1 } )
331
- . maxTimeMS ( 10 )
332
- . out ( 'collection' )
333
- . project ( { project : 1 } )
334
- . redact ( { redact : 1 } )
335
- . skip ( 1 )
336
- . sort ( { sort : 1 } )
337
- . batchSize ( 10 )
338
- . unwind ( 'name' ) ;
339
-
340
- // Execute the command with all steps defined
341
- // will fail
342
- const err = await cursor . toArray ( ) . catch ( err => err ) ;
343
- expect ( err ) . to . be . instanceof ( MongoServerError ) ;
344
- } ) ;
318
+ // TODO(NODE-7219): Remove test as it doesn't test correct aggregation execution
319
+ // it('allMethods', async function () {
320
+ // const cursor = db.collection('t1').aggregate([{ $match: {} }], {
321
+ // allowDiskUse: true,
322
+ // batchSize: 2,
323
+ // maxTimeMS: 50
324
+ // });
325
+ //
326
+ // // Exercise all the options
327
+ // cursor
328
+ // .geoNear({ geo: 1 })
329
+ // .group({ group: 1 })
330
+ // .limit(10)
331
+ // .match({ match: 1 })
332
+ // .maxTimeMS(10)
333
+ // .out('collection')
334
+ // .project({ project: 1 })
335
+ // .redact({ redact: 1 })
336
+ // .skip(1)
337
+ // .sort({ sort: 1 })
338
+ // .batchSize(10)
339
+ // .unwind('name');
340
+ //
341
+ // // Execute the command with all steps defined
342
+ // // will fail
343
+ // const err = await cursor.toArray().catch(err => err);
344
+ // expect(err).to.be.instanceof(MongoServerError);
345
+ // });
345
346
346
347
it ( '#toArray()' , async function ( ) {
347
348
const cursor = db . collection ( 't1' ) . aggregate ( ) ;
@@ -475,74 +476,68 @@ describe('CRUD API', function () {
475
476
} ) ;
476
477
} ) ;
477
478
478
- describe (
479
- 'should correctly execute update methods using crud api' ,
480
- {
481
- requires : { topology : [ 'single' , 'replicaset' , 'sharded' ] }
482
- } ,
483
- function ( ) {
484
- it ( 'legacy update' , async function ( ) {
485
- const db = client . db ( ) ;
486
- const r = await db
487
- . collection ( 't3_1' )
488
- // @ts -expect-error Not allowed in TS, but allowed for legacy compat
489
- . update ( { a : 1 } , { $set : { a : 2 } } , { upsert : true } ) ;
490
- expect ( r ) . property ( 'upsertedCount ') . to . equal ( 1 ) ;
491
- } ) ;
479
+ describe ( 'should correctly execute update methods using crud api' , function ( ) {
480
+ // TODO(NODE-7219): Remove test. There is no `update` method anymore
481
+ // it('legacy update', async function () {
482
+ // const db = client.db();
483
+ // const r = await db
484
+ // .collection('t3_1')
485
+ // . update({ a: 1 }, { $set: { a: 2 } }, { upsert: true });
486
+ // expect(r).property('upsertedCount').to.equal(1 );
487
+ // });
488
+
489
+ it ( '#updateOne()' , async function ( ) {
490
+ const db = client . db ( ) ;
491
+ const i = await db . collection ( 't3_2 ') . insertMany ( [ { c : 1 } ] , { writeConcern : { w : 1 } } ) ;
492
+ expect ( i ) . property ( 'insertedCount' ) . to . equal ( 1 ) ;
492
493
493
- it ( '#updateOne()' , async function ( ) {
494
- const db = client . db ( ) ;
495
- const i = await db . collection ( 't3_2' ) . insertMany ( [ { c : 1 } ] , { writeConcern : { w : 1 } } ) ;
496
- expect ( i ) . property ( 'insertedCount' ) . to . equal ( 1 ) ;
497
-
498
- const u1 = await db
499
- . collection ( 't3_2' )
500
- . updateOne ( { a : 1 } , { $set : { a : 1 } } , { upsert : true } ) ;
501
- expect ( u1 ) . property ( 'upsertedCount' ) . to . equal ( 1 ) ;
502
- test . equal ( 0 , u1 . matchedCount ) ;
503
- test . ok ( u1 . upsertedId != null ) ;
504
-
505
- const u2 = await db . collection ( 't3_2' ) . updateOne ( { c : 1 } , { $set : { a : 1 } } ) ;
506
- expect ( u2 ) . property ( 'modifiedCount' ) . to . equal ( 1 ) ;
507
- test . equal ( 1 , u2 . matchedCount ) ;
508
- test . ok ( u2 . upsertedId == null ) ;
509
- } ) ;
494
+ const u1 = await db
495
+ . collection ( 't3_2' )
496
+ . updateOne ( { a : 1 } , { $set : { a : 1 } } , { upsert : true } ) ;
497
+ expect ( u1 ) . property ( 'upsertedCount' ) . to . equal ( 1 ) ;
498
+ test . equal ( 0 , u1 . matchedCount ) ;
499
+ test . ok ( u1 . upsertedId != null ) ;
510
500
511
- it ( '#replaceOne()' , async function ( ) {
512
- const db = client . db ( ) ;
513
- const r1 = await db . collection ( 't3_3' ) . replaceOne ( { a : 1 } , { a : 2 } , { upsert : true } ) ;
514
- expect ( r1 ) . property ( 'upsertedCount' ) . to . equal ( 1 ) ;
515
- test . equal ( 0 , r1 . matchedCount ) ;
516
- test . ok ( r1 . upsertedId != null ) ;
517
-
518
- const r2 = await db . collection ( 't3_3' ) . replaceOne ( { a : 2 } , { a : 3 } , { upsert : true } ) ;
519
- expect ( r2 ) . property ( 'modifiedCount' ) . to . equal ( 1 ) ;
520
- expect ( r2 ) . property ( 'upsertedCount' ) . to . equal ( 0 ) ;
521
- expect ( r2 ) . property ( 'matchedCount' ) . to . equal ( 1 ) ;
522
- } ) ;
501
+ const u2 = await db . collection ( 't3_2' ) . updateOne ( { c : 1 } , { $set : { a : 1 } } ) ;
502
+ expect ( u2 ) . property ( 'modifiedCount' ) . to . equal ( 1 ) ;
503
+ test . equal ( 1 , u2 . matchedCount ) ;
504
+ test . ok ( u2 . upsertedId == null ) ;
505
+ } ) ;
523
506
524
- it ( '#updateMany()' , async function ( ) {
525
- const db = client . db ( ) ;
526
- const i = await db
527
- . collection ( 't3_4' )
528
- . insertMany ( [ { a : 1 } , { a : 1 } ] , { writeConcern : { w : 1 } } ) ;
529
- expect ( i ) . property ( 'insertedCount' ) . to . equal ( 2 ) ;
530
-
531
- const u1 = await db
532
- . collection ( 't3_4' )
533
- . updateMany ( { a : 1 } , { $set : { a : 2 } } , { upsert : true , writeConcern : { w : 1 } } ) ;
534
- expect ( u1 ) . property ( 'modifiedCount' ) . to . equal ( 2 ) ;
535
- test . equal ( 2 , u1 . matchedCount ) ;
536
- test . ok ( u1 . upsertedId == null ) ;
537
-
538
- const u2 = await db
539
- . collection ( 't3_4' )
540
- . updateMany ( { c : 1 } , { $set : { d : 2 } } , { upsert : true , writeConcern : { w : 1 } } ) ;
541
- test . equal ( 0 , u2 . matchedCount ) ;
542
- test . ok ( u2 . upsertedId != null ) ;
543
- } ) ;
544
- }
545
- ) ;
507
+ it ( '#replaceOne()' , async function ( ) {
508
+ const db = client . db ( ) ;
509
+ const r1 = await db . collection ( 't3_3' ) . replaceOne ( { a : 1 } , { a : 2 } , { upsert : true } ) ;
510
+ expect ( r1 ) . property ( 'upsertedCount' ) . to . equal ( 1 ) ;
511
+ test . equal ( 0 , r1 . matchedCount ) ;
512
+ test . ok ( r1 . upsertedId != null ) ;
513
+
514
+ const r2 = await db . collection ( 't3_3' ) . replaceOne ( { a : 2 } , { a : 3 } , { upsert : true } ) ;
515
+ expect ( r2 ) . property ( 'modifiedCount' ) . to . equal ( 1 ) ;
516
+ expect ( r2 ) . property ( 'upsertedCount' ) . to . equal ( 0 ) ;
517
+ expect ( r2 ) . property ( 'matchedCount' ) . to . equal ( 1 ) ;
518
+ } ) ;
519
+
520
+ it ( '#updateMany()' , async function ( ) {
521
+ const db = client . db ( ) ;
522
+ const i = await db
523
+ . collection ( 't3_4' )
524
+ . insertMany ( [ { a : 1 } , { a : 1 } ] , { writeConcern : { w : 1 } } ) ;
525
+ expect ( i ) . property ( 'insertedCount' ) . to . equal ( 2 ) ;
526
+
527
+ const u1 = await db
528
+ . collection ( 't3_4' )
529
+ . updateMany ( { a : 1 } , { $set : { a : 2 } } , { upsert : true , writeConcern : { w : 1 } } ) ;
530
+ expect ( u1 ) . property ( 'modifiedCount' ) . to . equal ( 2 ) ;
531
+ test . equal ( 2 , u1 . matchedCount ) ;
532
+ test . ok ( u1 . upsertedId == null ) ;
533
+
534
+ const u2 = await db
535
+ . collection ( 't3_4' )
536
+ . updateMany ( { c : 1 } , { $set : { d : 2 } } , { upsert : true , writeConcern : { w : 1 } } ) ;
537
+ test . equal ( 0 , u2 . matchedCount ) ;
538
+ test . ok ( u2 . upsertedId != null ) ;
539
+ } ) ;
540
+ } ) ;
546
541
547
542
describe ( '#findOneAndDelete' , function ( ) {
548
543
let collection : Collection ;
@@ -771,80 +766,63 @@ describe('CRUD API', function () {
771
766
} ) ;
772
767
} ) ;
773
768
774
- it ( 'should correctly execute removeMany with no selector' , {
775
- metadata : {
776
- requires : { topology : [ 'single' , 'replicaset' , 'sharded' ] }
777
- } ,
778
-
779
- test : async function ( ) {
780
- const db = client . db ( ) ;
781
- // Delete all items with no selector
782
- await db . collection ( 't6_1' ) . deleteMany ( ) ;
783
- }
769
+ it ( 'should correctly execute removeMany with no selector' , async function ( ) {
770
+ const db = client . db ( ) ;
771
+ // Delete all items with no selector
772
+ await db . collection ( 't6_1' ) . deleteMany ( ) ;
784
773
} ) ;
785
774
786
- it ( 'should correctly execute crud operations with w:0' , {
787
- metadata : {
788
- requires : { topology : [ 'single' , 'replicaset' , 'sharded' ] }
789
- } ,
790
-
791
- test : async function ( ) {
792
- const db = client . db ( ) ;
775
+ it ( 'should correctly execute crud operations with w:0' , async function ( ) {
776
+ const db = client . db ( ) ;
793
777
794
- const col = db . collection ( 'shouldCorrectlyExecuteInsertOneWithW0' ) ;
795
- const i1 = await col . insertOne ( { a : 1 } , { writeConcern : { w : 0 } } ) ;
796
- expect ( i1 ) . property ( 'acknowledged' ) . to . be . false ;
797
- expect ( i1 ) . property ( 'insertedId' ) . to . exist ;
778
+ const col = db . collection ( 'shouldCorrectlyExecuteInsertOneWithW0' ) ;
779
+ const i1 = await col . insertOne ( { a : 1 } , { writeConcern : { w : 0 } } ) ;
780
+ expect ( i1 ) . property ( 'acknowledged' ) . to . be . false ;
781
+ expect ( i1 ) . property ( 'insertedId' ) . to . exist ;
798
782
799
- const i2 = await col . insertMany ( [ { a : 1 } ] , { writeConcern : { w : 0 } } ) ;
800
- expect ( i2 ) . to . exist ;
783
+ const i2 = await col . insertMany ( [ { a : 1 } ] , { writeConcern : { w : 0 } } ) ;
784
+ expect ( i2 ) . to . exist ;
801
785
802
- const u1 = await col . updateOne ( { a : 1 } , { $set : { b : 1 } } , { writeConcern : { w : 0 } } ) ;
803
- expect ( u1 ) . to . exist ;
786
+ const u1 = await col . updateOne ( { a : 1 } , { $set : { b : 1 } } , { writeConcern : { w : 0 } } ) ;
787
+ expect ( u1 ) . to . exist ;
804
788
805
- const u2 = await col . updateMany ( { a : 1 } , { $set : { b : 1 } } , { writeConcern : { w : 0 } } ) ;
806
- expect ( u2 ) . to . exist ;
789
+ const u2 = await col . updateMany ( { a : 1 } , { $set : { b : 1 } } , { writeConcern : { w : 0 } } ) ;
790
+ expect ( u2 ) . to . exist ;
807
791
808
- const d1 = await col . deleteOne ( { a : 1 } , { writeConcern : { w : 0 } } ) ;
809
- expect ( d1 ) . to . exist ;
792
+ const d1 = await col . deleteOne ( { a : 1 } , { writeConcern : { w : 0 } } ) ;
793
+ expect ( d1 ) . to . exist ;
810
794
811
- const d2 = await col . deleteMany ( { a : 1 } , { writeConcern : { w : 0 } } ) ;
812
- expect ( d2 ) . to . exist ;
813
- }
795
+ const d2 = await col . deleteMany ( { a : 1 } , { writeConcern : { w : 0 } } ) ;
796
+ expect ( d2 ) . to . exist ;
814
797
} ) ;
815
798
816
- it ( 'should correctly execute updateOne operations with w:0 and upsert' , {
817
- metadata : {
818
- requires : { topology : [ 'single' , 'replicaset' , 'sharded' ] }
819
- } ,
820
-
821
- test : async function ( ) {
822
- const db = client . db ( ) ;
799
+ it ( 'should correctly execute updateOne operations with w:0 and upsert' , async function ( ) {
800
+ const db = client . db ( ) ;
823
801
824
- const r = await db
825
- . collection < { _id : number } > ( 'try' )
826
- . updateOne ( { _id : 1 } , { $set : { x : 1 } } , { upsert : true , writeConcern : { w : 0 } } ) ;
827
- test . ok ( r != null ) ;
828
- }
802
+ const r = await db
803
+ . collection < { _id : number } > ( 'try' )
804
+ . updateOne ( { _id : 1 } , { $set : { x : 1 } } , { upsert : true , writeConcern : { w : 0 } } ) ;
805
+ test . ok ( r != null ) ;
829
806
} ) ;
830
807
831
- it ( 'should correctly execute crud operations using w:0' , {
832
- metadata : {
833
- requires : { topology : [ 'single' , 'replicaset' , 'sharded' ] }
834
- } ,
835
-
836
- test : async function ( ) {
837
- const db = client . db ( ) ;
838
-
839
- const collection = db . collection < { _id : number } > ( 'w0crudoperations' ) ;
840
- const r = await collection . updateOne (
841
- { _id : 1 } ,
842
- { $set : { x : 1 } } ,
843
- { upsert : true , writeConcern : { w : 0 } }
844
- ) ;
845
- test . ok ( r != null ) ;
846
- }
847
- } ) ;
808
+ // TODO(NODE-7219): Remove test as it duplicates the one from the above
809
+ // it('should correctly execute crud operations using w:0', {
810
+ // metadata: {
811
+ // requires: { topology: ['single', 'replicaset', 'sharded'] }
812
+ // },
813
+ //
814
+ // test: async function () {
815
+ // const db = client.db();
816
+ //
817
+ // const collection = db.collection<{ _id: number }>('w0crudoperations');
818
+ // const r = await collection.updateOne(
819
+ // { _id: 1 },
820
+ // { $set: { x: 1 } },
821
+ // { upsert: true, writeConcern: { w: 0 } }
822
+ // );
823
+ // test.ok(r != null);
824
+ // }
825
+ // });
848
826
849
827
describe ( 'when performing a multi-batch unordered bulk write that has a duplicate key' , function ( ) {
850
828
it ( 'throws a MongoBulkWriteError indicating the duplicate key document failed' , async function ( ) {
@@ -872,28 +850,22 @@ describe('CRUD API', function () {
872
850
} ) ;
873
851
} ) ;
874
852
875
- it ( 'should correctly throw error on illegal callback when ordered bulkWrite encounters error' , {
876
- metadata : {
877
- requires : { topology : [ 'single' , 'replicaset' , 'sharded' ] }
878
- } ,
879
-
880
- test : async function ( ) {
881
- const ops = [ ] ;
882
- // Create a set of operations that go over the 1000 limit causing two messages
883
- let i = 0 ;
884
- for ( ; i < 1005 ; i ++ ) {
885
- ops . push ( { insertOne : { _id : i , a : i } } ) ;
886
- }
853
+ it ( 'should throw an error when ordered bulkWrite encounters error' , async function ( ) {
854
+ const ops = [ ] ;
855
+ // Create a set of operations that go over the 1000 limit causing two messages
856
+ let i = 0 ;
857
+ for ( ; i < 1005 ; i ++ ) {
858
+ ops . push ( { insertOne : { _id : i , a : i } } ) ;
859
+ }
887
860
888
- ops . push ( { insertOne : { _id : 0 , a : i } } ) ;
861
+ ops . push ( { insertOne : { _id : 0 , a : i } } ) ;
889
862
890
- const db = client . db ( ) ;
891
- const err = await db
892
- . collection ( 't20_1' )
893
- . bulkWrite ( ops , { ordered : true , writeConcern : { w : 1 } } )
894
- . catch ( err => err ) ;
895
- expect ( err ) . to . be . instanceOf ( MongoBulkWriteError ) ;
896
- }
863
+ const db = client . db ( ) ;
864
+ const err = await db
865
+ . collection ( 't20_1' )
866
+ . bulkWrite ( ops , { ordered : true , writeConcern : { w : 1 } } )
867
+ . catch ( err => err ) ;
868
+ expect ( err ) . to . be . instanceOf ( MongoBulkWriteError ) ;
897
869
} ) ;
898
870
899
871
describe ( 'sort support' , function ( ) {
0 commit comments