I installed passport-local-mongoose package and when I used this:
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);
It throws an error:
userSchema.plugin is not a function
The error is becuase
userSchemais just a POJO so it doesn't have any mongoose methods inherited.You need to create a new instance of the mongoose Schema like so: