StackOverLow
StackOverLow

Reputation: 45

Unresolved function or method findOne()

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

Answers (1)

Sagar Jajoriya
Sagar Jajoriya

Reputation: 2375

User.findOne({where: {username: req.params.username}}, function(err,foundUser){
    //rest of code
})

Upvotes: 1

Related Questions