【发布时间】:2019-09-30 08:12:51
【问题描述】:
我正在尝试使用 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);
当我从终端使用命令db.usertable.find({}) 在mongo shell 中执行查询时,我可以看到结果仍然有username 字段。从架构文件中删除 username 字段后,我也尝试过,但即使这样也无济于事。
提前致谢。
【问题讨论】:
标签: javascript node.js mongoose