Reputation:
Here is my model in mongoose from which i have to authenticate the user name and password
var employee =
{
empCode : { type : String , unique: true , required : true },
firstName : { type : String , required : true },
lastName : { type : String },
email : { type : String },
DOJ :{ type : Date , default: Date.now },
DOB :{ type : Date },
phoneNo : { type : String },
authentication :
{
username : { type : String },
password : { type : String }
},
status : {type:Boolean}
};
I want to check with authentication in login what i am trying is
loginController.prototype.userValidator = function(req , callback){
objDB.selectOne(objMdlEmployee , { authentication.username : req.username , authentication.password : req.password } , function(err , ObjDocument){
if(err){
callback(false , config.msg.SOMTHING_WRONG);
}else if(ObjDocument===null){
callback(false , config.msg.AUTH_FAIL);
}
else {
req.session.sessUser = {
userAuthenticate : true,
firstName : ObjDocument.firstName,
employeeId : ObjDocument.employeeId
}
callback(true , 'Valid');
}
});
};
but it is giving me error
Unexpected token . at authentication.username
how can i achieve this ?
Upvotes: 0
Views: 41
Reputation: 597
Subfields must be quoted like:
objDB.selectOne(objMdlEmployee , { 'authentication.username' : req.username , 'authentication.password' : req.password } , function(err , ObjDocument){
Upvotes: 1