The query to the database returns the correct object but I'm having trouble accessing the values of the members of the object.
Here's my code:
socket.on("getUser", function(username){
User.find({username: username}, function (err, user)
{
console.log("*** " + user + " \n*** " + typeof user);
console.log(user.username);
if (err) console.log(err);
else {
socket.emit("getUserResponse", user);
}
})
});
The output from this is:
*** { ticketsPurchased: [],
_id: 5add436fb3da1931c8a64de6,
username: 'nekumes@emailure.net',
password: 'test',
firstName: 'abc',
lastName: 'abd',
admin: false,
__v: 0 }
*** Type = object
*** undefined
Why can't I access the value of username? It works fine when I output the user object. Please help!