【问题标题】:Mongoose keeps creating indexes for old fields that do not exist anymoreMongoose 不断为不再存在的旧字段创建索引
【发布时间】:2018-03-25 20:31:54
【问题描述】:

所以我有一个具有usernamepassword 字段的模型用户。后来我将其更改为使用电子邮件而不是用户名。在另一个模型上进行了类似的更改 - 我将 username 重命名为 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 })

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

【问题讨论】:

    标签: mongodb mongoose mongoose-schema mongoose-plugins


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-12-18
      • 2012-09-09
      • 2012-09-16
      • 2015-01-09
      • 2023-03-26
      • 2017-09-04
      • 2018-07-03
      • 1970-01-01
      相关资源
      最近更新 更多