I'm using meteor js w/ simple-schema and getting
MongoError: Index with pattern: { username: 1 } already exists with different options
My schema around the db.users collection is
Schema = {};
Schema.User = new SimpleSchema({
...
username: {
type: String,
unique: true,
regEx: /^[a-z0-9]{3,32}$/ ,
max: 32,
min: 3 },
...
});
I've dropped the index in mongodb but am still getting the error when I restart my app. Anyone come across this ?
Meteor comes with some default indexes on the users
collections. From accounts-base :
/// DEFAULT INDEXES ON USERS
Meteor.users._ensureIndex('username', {unique: 1, sparse: 1});
Meteor.users._ensureIndex('emails.address', {unique: 1, sparse: 1});
Meteor.users._ensureIndex('services.resume.loginTokens.hashedToken',
{unique: 1, sparse: 1});
Meteor.users._ensureIndex('services.resume.loginTokens.token',
{unique: 1, sparse: 1});
// For taking care of logoutOtherClients calls that crashed before the tokens
// were deleted.
Meteor.users._ensureIndex('services.resume.haveLoginTokensToDelete',
{ sparse: 1 });
// For expiring login tokens
Meteor.users._ensureIndex("services.resume.loginTokens.when", { sparse: 1 });
I have not checked but I'm guessing unique: true
may be the part of your schema that is conflicting with the above.
you can perfectly merge your schema with the existing one where index and unique is already set for username and email. as you only remove them by setting them explicitly to false they will remain.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.