Reputation: 45
I've a user.js file which is used for the user model in my website. This is the user schema:
var UserSchema = mongoose.Schema({
username: {
type: String,
index:true
},
password: {
type: String
},
email: {
type: String
},
name: {
type: String
},
avatar: {
type: String
}
});
UserSchema.plugin(passportLocalMongoose);
var User = module.exports = mongoose.model('User', UserSchema);
When I wanted to use the function findOne() in another file for the user profile, it gave me the error that I typed in the title.
This is the file's code:
var User = require('../models/user.js');
router.get("/:username", function(req,res){
User.findOne(req.params.username, function(err,foundUser){
if(err){
req.flash("error", "Something went wrong.");
return res.redirect("/");
}
res.render("show",{user:foundUser});
})
});
Upvotes: 0
Views: 736
Reputation: 2375
User.findOne({where: {username: req.params.username}}, function(err,foundUser){
//rest of code
})
Upvotes: 1