here is my complete code
var express = require(\'express\'),
app = express(),
mongoose = require(\'mongoose\'),
bodyParser = require(\'body-parse
In your User Schema, you are setting select
to false for the password field. This means that anytime you look for a user in the schema as you're trying to do in the login
request, you won't get the value of the password
field or any other field that has select
false defined in the schema.
What you need to do is to specify you need the password when the user is found:
app.post('/login', function(req, res){
userModel.findOne({username: req.body.username}, 'password', function(err, user){
// continue
}
This will return only the _id
and the password
from the DB. If you want to return other fields, you'd have to add them in:
app.post('/login', function(req, res){
userModel.findOne({username: req.body.username}, 'password firstName lastName email', function(err, user){
// continue
}