简体   繁体   English

流星js simpleschema带有模式的索引已存在不同的选项

[英]meteor js simpleschema Index with pattern already exists with different options

I'm using meteor js w/ simple-schema and getting 我正在使用带有简单模式的流星js并获得

MongoError: Index with pattern: { username: 1 } already exists with different options

My schema around the db.users collection is 我围绕db.users集合的模式是

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. 我在mongodb中删除了索引,但是重新启动应用程序时仍然出现错误。 Anyone come across this ? 有人遇到这个吗?

Meteor comes with some default indexes on the users collections. 流星自带的一些默认指标users集合。 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. 我没有检查,但我猜unique: true可能是你的架构是与上述相冲突的部分。

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. 因为您仅通过将它们显式设置为false来删除它们,否则它们将保留。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 猫鼬指数已经存在不同的选择 - mongoose index already exists with different options 猫鼬/ Mongodb:索引已存在具有不同的选项 - Mongoose/Mongodb: Index Already Exists With Different Options 流星js:使用validatedmethod simpleschema获取完整的验证消息 - Meteor js: get full validation message with validatedmethod simpleschema 如何在subschema Meteor js 1.8中声明simpleschema或 - How to declare simpleschema OR within subschema Meteor js 1.8 流星SimpleSchema重复嵌套对象 - Meteor SimpleSchema Repeated Nested Objects 有没有一种方法可以重复使用模板,以使用流星SimpleSchema + Autoforms将数据存储到不同的相同集合中? - Is there a way to reuse a template for storing data into different identical collections using meteor SimpleSchema + Autoforms? meteor.js“ tsega:bootstrap3-datetimepicker”使用SimpleSchema“ type:Date”记录数据 - meteor.js “tsega:bootstrap3-datetimepicker” record data using the SimpleSchema “type: Date” Meteor.js遍历数组以检查集合文档中是否已存在值 - Meteor.js Loop over an array to check if value already exists in collection documents 在Meteor AutoForm SimpleSchema中验证日期值 - Validate date values in Meteor AutoForm SimpleSchema 流星服务器在SimpleSchema autoValue选项上崩溃 - Meteor server is crashing on SimpleSchema autoValue option
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM