@@ -7563,68 +7563,31 @@ describe('Model', function() {
7563
7563
7564
7564
} ) ;
7565
7565
it ( 'Using bulkSave should not trigger an error (gh-11071)' , async function ( ) {
7566
-
7567
- class TestModel {
7568
- static _instance
7569
- _model ;
7570
-
7571
- /**
7572
- * @private
7573
- */
7574
- constructor ( ) { }
7575
-
7576
- static create ( ) {
7577
- if ( this . _instance ) { return this . _instance ; }
7578
- this . _instance = new this ( ) ;
7579
-
7580
- let pairSchema = mongoose . Schema ( {
7581
- name : String ,
7582
- timestamp : String
7583
- } , { versionKey : false } ) ;
7584
-
7585
- this . _instance . _model = db . model ( 'test' , pairSchema ) ;
7586
-
7587
- return this . _instance ;
7588
- }
7589
7566
7590
- async insertTests ( ) {
7591
-
7592
- const tests = [
7593
- { name : 't1' , timestamp : Date . now ( ) } ,
7594
- { name : 't2' , timestamp : Date . now ( ) } ,
7595
- { name : 't3' , timestamp : Date . now ( ) } ,
7596
- { name : 't4' , timestamp : Date . now ( ) } ,
7597
- ] ;
7598
-
7599
- try {
7600
- return this . _model . insertMany ( tests , {
7601
- ordered : false
7602
- } ) ;
7603
- }
7604
- catch ( err ) {
7605
- throw new Error ( `${ this . constructor . name } insertMany: ${ err } ` ) ;
7606
- }
7607
- }
7567
+ const pairSchema = mongoose . Schema ( {
7568
+ name : String ,
7569
+ timestamp : String
7570
+ } , { versionKey : false } ) ;
7608
7571
7609
- async all ( ) {
7610
- return await this . _model . find ( { } ) ;
7611
- }
7612
-
7613
- async bulkSaveTest ( tests ) {
7614
- for ( let p of tests ) {
7615
- p . timestamp = Date . now ( ) ;
7616
- }
7617
-
7618
- // !!! "TypeError: path.indexOf is not a function" occurs here
7619
- let res = await this . _model . bulkSave ( tests ) ;
7620
- return res ;
7621
- }
7622
-
7623
- }
7624
- const testModel = TestModel . create ( ) ;
7625
- await testModel . insertTests ( ) ;
7626
- let tests = await testModel . all ( ) ;
7627
- assert . ok ( await testModel . bulkSaveTest ( tests ) ) ;
7572
+ const model = db . model ( 'test' , pairSchema ) ;
7573
+ const tests = [
7574
+ { name : 't1' , timestamp : Date . now ( ) } ,
7575
+ { name : 't2' , timestamp : Date . now ( ) } ,
7576
+ { name : 't3' , timestamp : Date . now ( ) } ,
7577
+ { name : 't4' , timestamp : Date . now ( ) } ,
7578
+ ] ;
7579
+
7580
+ model . insertMany ( tests , {
7581
+ ordered : false
7582
+ } ) ;
7583
+ const entries = await model . find ( { } ) ;
7584
+ for ( const p of entries ) {
7585
+ p . timestamp = Date . now ( ) ;
7586
+ }
7587
+
7588
+ // !!! "TypeError: path.indexOf is not a function" occurs here
7589
+ const res = await model . bulkSave ( entries ) ;
7590
+ assert . ok ( res ) ;
7628
7591
} ) ;
7629
7592
} ) ;
7630
7593
0 commit comments