You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
thrownewMongooseError(`Schema already has an index on ${JSON.stringify(fields)}`);
2151
+
utils.warn(`Duplicate schema index on ${JSON.stringify(fields)} found. This is often due to declaring an index using both "index: true" and "schema.index()". Please remove the duplicate index definition.`);
it('throws "already has an index" error if duplicate index definition (gh-15056)',function(){
3282
-
constObjectKeySchema=newmongoose.Schema({
3283
-
key: {
3284
-
type: String,
3285
-
required: true,
3286
-
unique: true
3287
-
},
3288
-
type: {
3289
-
type: String,
3290
-
required: false
3291
-
}
3292
-
});
3283
+
sinon.stub(utils,'warn').callsFake(()=>{});
3284
+
try{
3285
+
constObjectKeySchema=newmongoose.Schema({
3286
+
key: {
3287
+
type: String,
3288
+
required: true,
3289
+
unique: true
3290
+
},
3291
+
type: {
3292
+
type: String,
3293
+
required: false
3294
+
}
3295
+
});
3293
3296
3294
-
assert.throws(()=>{
3295
3297
ObjectKeySchema.index({key: 1});
3296
-
},/MongooseError.*alreadyhasanindex/);
3298
+
assert.equal(utils.warn.getCalls().length,1);
3299
+
let[message]=utils.warn.getCalls()[0].args;
3300
+
assert.equal(
3301
+
message,
3302
+
'Duplicate schema index on {"key":1} found. This is often due to declaring an index using both "index: true" and "schema.index()". Please remove the duplicate index definition.'
'Duplicate schema index on {"key":1,"type":1} found. This is often due to declaring an index using both "index: true" and "schema.index()". Please remove the duplicate index definition.'
0 commit comments