I can't get a result from a mongoDb, see my code
//connect user
getUser = function(login, password, callback){
models.user.find({
password: global.helper.encode(password),
$or : [ {
username : login
} , {
mail : login
} ]
},function(err, result){
console.log(result)
console.log(result.username)
callback(result);
})
}
console.log(result) return :
[ { username: 'ant',
mail: 'aa@aa.aa',
password: '7e240de74fb1ed08fa08d38063f6a6a91462a815',
date_register: Sun, 18 Nov 2012 11:58:45 GMT,
date_login: Sun, 18 Nov 2012 11:58:45 GMT,
_id: 50a8cd75494a6db815000001,
__v: 0 } ]
and console.log(result.username) return undefined
I also try result['username'] but I have undefined too
thanks for your help
The results are returned as a JSON object which is an object within an array. You almost had it, but you should do console.log(result[0].username)
which will return what you need.