vendredi 20 février 2015

Why Mongoose is responding null field when it exists in DB

I don't know if this a mongoose bug or I'm doing something wrong, my problem is:


I have some documents in the mongoDB these have an attribute called address and inside it have an country which is an object id but when I make a query using mongoose this country id comes as "null":


MongoDB document:



{
"_id" : ObjectId("54b7ff802d244c9f224c78f4"),
"password" : "12345",
"email" : "email@email.com",
// ...
"address" : {
"country" : ObjectId("54e635cb4ef1d41d99b837e8"),
"zipCode" : "",
"city" : "",
"address" : ""
}
}


Mongoose query



Model.findOne({
email: 'email@email.com',
password: '12345'
}, function(err, model) { /* ... */ });


Mongoose response



{
"_id": "54b7ff802d244c9f224c78f4",
"email": "email@email.com",
"password" : "12345",
// ...
"address": {
"country": null,
"zipCode": "",
"city": "",
"address": ""
}


}


I really don't know why country is coming as null. My Mongo version is 2.6.6 and mongoose version is 3.8.21.


Any ideas?


Aucun commentaire:

Enregistrer un commentaire