-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Copy link
Labels
developer-experienceThis issue improves error messages, debugging, or reportingThis issue improves error messages, debugging, or reporting
Milestone
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the issue has not already been raised
Issue
Error message
MongooseError: Schema already has an index on {"uid":1,"gid":1}
at Schema.index (xxx/node_modules/mongoose/lib/schema.js:2151:13)
at Object.<anonymous> (xx/schema/member.js:20:8)
Schema
/* eslint-disable */
const mongoose = require('mongoose');
const _schema = {
uid: {type: mongoose.Schema.Types.ObjectId, required: true},
gid: {type: mongoose.Schema.Types.ObjectId, required: true},
};
const schema = new mongoose.Schema(
_schema,
{'versionKey': false, 'usePushEach': true, 'minimize': false, 'shardKey': {'uid': 1}}
);
schema.index({'�gid': 1, 'uid': 1}, {background: false});
schema.index({'uid': 1, 'gid': 1}, {background: false});
mongoDB
test> db.test.createIndex({uid: 1, gid:1})
uid_1_gid_1
test> db.test.createIndex({uid: 1, gid:1})
uid_1_gid_1
test> db.test.getIndexes()
[
{ v: 2, key: { gid: 1, uid: 1 }, name: 'gid_1_uid_1' },
{ v: 2, key: { uid: 1, gid: 1 }, name: 'uid_1_gid_1' }
]
In my opinion, the two indexes seem to work differently in MongoDB.
why is this causing an error in mongoose? It works correctly in mongoose@8.8.x, but it behaves abnormally in mongoose@8.9.1.
ahmednaser94, ronenteva, ilkkaparssinen, djflyte, ViaSocket-Git and 4 more
Metadata
Metadata
Assignees
Labels
developer-experienceThis issue improves error messages, debugging, or reportingThis issue improves error messages, debugging, or reporting