@@ -1079,11 +1079,32 @@ describe('connections:', function() {
1079
1079
assert . deepStrictEqual ( conn3 . id , m . connection . id + 2 ) ;
1080
1080
} ) ;
1081
1081
1082
- it ( 'Allows a syncIndexes option (gh-10893)' , async function ( ) {
1082
+ it ( 'Allows a syncIndexes option with connection mongoose.connection.syncIndexes (gh-10893)' , async function ( ) {
1083
+ this . timeout ( 10000 ) ;
1084
+
1085
+
1086
+ const coll = 'tests2' ;
1083
1087
const m = new mongoose . Mongoose ( ) ;
1084
1088
const conn = m . createConnection ( 'mongodb://localhost:27017' ) ;
1085
- conn . model ( 'Test' , new Schema ( { name : { type : String , index : true } } ) ) ;
1089
+ let M = conn . model ( 'Test' , new Schema ( { name : { type : String , index : true } } , { autoIndex : false } ) , coll ) ;
1086
1090
const sync = await conn . syncIndexes ( ) ;
1087
1091
assert ( sync , [ [ ] ] ) ;
1092
+ let indexes = await M . listIndexes ( ) ;
1093
+ assert . deepEqual ( indexes . map ( i => i . key ) , [
1094
+ { _id : 1 } ,
1095
+ { name : 1 }
1096
+ ] ) ;
1097
+ conn . deleteModel ( / T e s t / ) ;
1098
+ M = conn . model ( 'Test' , new Schema ( {
1099
+ otherName : { type : String , index : true }
1100
+ } , { autoIndex : false } ) , coll ) ;
1101
+ const dropped = await conn . syncIndexes ( ) ;
1102
+ assert . deepEqual ( dropped , [ [ 'name_1' ] ] ) ;
1103
+ await M . collection . drop ( ) ;
1104
+ } ) ;
1105
+ it ( 'Allows a syncIndexes shorthand mongoose.syncIndexes (gh-10893)' , async function ( ) {
1106
+ // const m = new mongoose.Mongoose();
1107
+ // console.log(m.syncIndexes());
1108
+ assert ( true , true )
1088
1109
} ) ;
1089
1110
} ) ;
0 commit comments