我安装了passport-local-mongoose
包,当我使用这个:
const mongoose = require("mongoose");
const plm = require("passport-local-mongoose");
mongoose.connect(
`mongodb+srv://Funn:[email protected]/`,
{
dbName: "Auth"
}
).then((c) => console.log("db connected",c.connection.host))
.catch((e) => console.log(e));
const userSchema = {
username: String,
password: String,
secret:String,
}
userSchema.plugin(plm);// because of this line it throw error
module.exports = mongoose.model("user", userSchema);
字符串
它抛出一个错误:
userSchema.plugin is not a function
型
1条答案
按热度按时间6ovsh4lw1#
这个错误是因为
userSchema
只是一个POJO,所以它没有继承任何mongoose方法。你需要创建一个mongoose Schema的新示例,如下所示:
字符串