javascript - 如何使用 mongoose 从 mongodb 模式中删除索引?
问题描述
我正在尝试使用 mongoose 从 node.js 应用程序中的 mongoDB 集合中删除索引。我尝试使用model.collection.dropIndex("username")
,但它给了我一个错误UnhandledPromiseRejectionWarning: MongoError: index not found with name [username]
。
这是我的架构
var mongoose = require("mongoose"),
Schema = mongoose.Schema;
var userTable = new Schema({
firstname: { type: String, required: true },
lastname: { type: String, required: true },
username: { type: String },
salt: { type: String },
passwordHash: { type: String },
email: { type: String, unique: true, required: true },
sessionToken: { type: String },
dateCreated: { type: String, default: new Date().toString() },
loginHistory: [String]
});
module.exports = mongoose.model("userTable", userTable);
当我使用 command 从终端在 mongo shell 中执行查询时db.usertable.find({})
,我可以看到结果仍然有username
字段。从架构文件中删除该字段后,我也尝试过username
,但即使这样也无济于事。
提前致谢。
解决方案
推荐阅读
- r - 从 sf 线串对象创建具有正确索引标签的 inla.graph 对象
- c++ - CMake无法在子目录中找到源文件
- flutter - 如何在 Tabar Flutter 中创建箭头?
- javascript - 有没有办法在不知道位置但属性的情况下从数组中删除对象?
- java - 调用 PATCH 端点时打开 api 生成的客户端失败
- r - 使用 ifelse 和 is.na 重新编码变量
- python - 根据 pandas 中的多个条件计算每一行的分数,避免 for 循环
- google-chrome-extension - 如何为 Safari 构建屏幕录制扩展
- summernote - 为什么summernote中工具栏的标题名称有时会像这样自动转换?
- nfc - ISO15693 NFC 标签中的 DSFID 和 AFI 字段的作用是什么?