I am finding one single document using findOne()
My document has userid as one of the key inside my users model.
Example
{
userid: 1,
name: 'John'
}
Now I am able to receive this document as object when I do the following
users.findOne({userid: 1}, function(e, data){
if(e){
return (res.send('Failed'))
}else{
return (res.send(data))
}
});
However, if I try to submit the same value of userid dynamically then the data obj returns null and still if(e) statement is not executed.
Example
users.findOne({userid: req.body.userid}, function(e, data){
if(e){
return (res.send('Failed'))
}else{
return (res.send(data))
}
});
I console logged the value of req.body.userid and checked that it is 1 when I pass it dynamically.
What am I doing wrong? Is the value of req.body.userid not passed correctly to userid key?