@@ -31,7 +31,7 @@ class MongooseAdapter extends BaseKeystoneAdapter {
3131 this . listAdapterClass = MongooseListAdapter ;
3232 this . name = 'mongoose' ;
3333 this . mongoose = new mongoose . Mongoose ( ) ;
34- this . minVer = '4 .0.0' ;
34+ this . minVer = '5 .0.0' ;
3535 if ( debugMongoose ( ) ) {
3636 this . mongoose . set ( 'debug' , true ) ;
3737 }
@@ -56,12 +56,7 @@ class MongooseAdapter extends BaseKeystoneAdapter {
5656 throw new Error ( `No MongoDB connection URI specified.` ) ;
5757 }
5858
59- await this . mongoose . connect ( uri , {
60- useNewUrlParser : true ,
61- useFindAndModify : false ,
62- useUnifiedTopology : true ,
63- ...mongooseConfig ,
64- } ) ;
59+ await this . mongoose . connect ( uri , mongooseConfig ) ;
6560 }
6661 async postConnect ( { rels } ) {
6762 // Setup all schemas
@@ -345,8 +340,8 @@ class MongooseListAdapter extends BaseListAdapter {
345340 return (
346341 await this . _getModel ( tableName ) . create (
347342 values . map ( id => ( {
348- [ near ] : mongoose . Types . ObjectId ( itemId ) ,
349- [ far ] : mongoose . Types . ObjectId ( id ) ,
343+ [ near ] : new mongoose . Types . ObjectId ( itemId ) ,
344+ [ far ] : new mongoose . Types . ObjectId ( id ) ,
350345 } ) )
351346 )
352347 ) . map ( x => x [ far ] ) ;
@@ -420,7 +415,7 @@ class MongooseListAdapter extends BaseListAdapter {
420415 }
421416 const currentRefIds = (
422417 await this . _getModel ( tableName ) . aggregate ( [
423- { $match : { [ matchCol ] : mongoose . Types . ObjectId ( item . id ) } } ,
418+ { $match : { [ matchCol ] : new mongoose . Types . ObjectId ( item . id ) } } ,
424419 ] )
425420 ) . map ( x => x [ selectCol ] . toString ( ) ) ;
426421
@@ -431,12 +426,12 @@ class MongooseListAdapter extends BaseListAdapter {
431426 await this . _getModel ( tableName ) . deleteMany ( {
432427 $and : [
433428 { [ matchCol ] : { $eq : item . _id } } ,
434- { [ selectCol ] : { $in : needsDelete . map ( id => mongoose . Types . ObjectId ( id ) ) } } ,
429+ { [ selectCol ] : { $in : needsDelete . map ( id => new mongoose . Types . ObjectId ( id ) ) } } ,
435430 ] ,
436431 } ) ;
437432 } else {
438433 await this . _getModel ( tableName ) . updateMany (
439- { [ selectCol ] : { $in : needsDelete . map ( id => mongoose . Types . ObjectId ( id ) ) } } ,
434+ { [ selectCol ] : { $in : needsDelete . map ( id => new mongoose . Types . ObjectId ( id ) ) } } ,
440435 { [ columnName ] : null }
441436 ) ;
442437 }
@@ -457,7 +452,7 @@ class MongooseListAdapter extends BaseListAdapter {
457452 }
458453
459454 async _delete ( id ) {
460- id = mongoose . Types . ObjectId ( id ) ;
455+ id = new mongoose . Types . ObjectId ( id ) ;
461456 // Traverse all other lists and remove references to this item
462457 // We can't just traverse our own fields, because we might have been
463458 // a silent partner in a relationship, so we have no self-knowledge of it.
@@ -521,14 +516,14 @@ class MongooseListAdapter extends BaseListAdapter {
521516 ids = await this . _getModel ( tableName ) . aggregate ( [
522517 {
523518 $match : {
524- [ columnNames [ columnKey ] . near ] : { $eq : mongoose . Types . ObjectId ( from . fromId ) } ,
519+ [ columnNames [ columnKey ] . near ] : { $eq : new mongoose . Types . ObjectId ( from . fromId ) } ,
525520 } ,
526521 } ,
527522 ] ) ;
528523 ids = ids . map ( x => x [ columnNames [ columnKey ] . far ] ) ;
529524 } else {
530525 ids = await this . _getModel ( tableName ) . aggregate ( [
531- { $match : { [ columnName ] : mongoose . Types . ObjectId ( from . fromId ) } } ,
526+ { $match : { [ columnName ] : new mongoose . Types . ObjectId ( from . fromId ) } } ,
532527 ] ) ;
533528 ids = ids . map ( x => x . _id ) ;
534529 }
0 commit comments