猫鼬一直为不存在的旧字段创建索引

问题描述:

所以我有一个模型用户usernamepassword字段。后来我改变它使用电子邮件,而不是用户名。另一个型号也进行了类似的更改 - 我将其更名为至name。这两个字段均使用来自mongoose-unique-validator的独特验证。现在,无论何时启动服务器,猫鼬都会为所有字段,新旧字段创建索引。第一个和最后一个东西不会在模式存在了:猫鼬一直为不存在的旧字段创建索引

Mongoose: users.ensureIndex({ username: 1 }, { unique: true, background: true }) 
Mongoose: people.ensureIndex({ name: 1 }, { unique: true, background: true }) 
Mongoose: people.ensureIndex({ uri: 1 }, { unique: true, background: true }) 
Mongoose: people.ensureIndex({ username: 1 }, { unique: true, background: true }) 

删除数据库没有帮助,更改数据库没有帮助。我真的不明白它可能来自哪里。猫鼬中是否存在某种缓存?

好的,原因是我错误地使用了passport-local-mongoose。它自动创建索引。我需要在选项中指定,而不仅仅是本地策略,我要用哪些字段来输入用户名和密码。而对于第二个模型,它只是被错误地插入。