vendredi 6 mars 2015

Why my mongoose objectId request return an empty array?

I past my day to find the answer, in vain.


this is my mongoose schema:



var schema = new mongoose.Schema({
value: {type: String},
title: {type: String},
date: { type: Date, default: Date.now },
packId: {type: mongoose.Schema.Types.ObjectId, ref:'Pack'}
});


this is my request:


( Where packId is a ObjectId )



var getElements = function(packId, callback ){
Card.find(
{packId: packId},
function(err,els){
if(err){
console.log(err);
}else{
console.log(els);
}
}
);
};


**And this is a table element **



{
"title" : "test1",
"value" : "test1",
"packId" : ObjectId("54f9ebaae312727c45b2a80e"),
"_id" : ObjectId("54f9ebaae312727c45b2a820"),
"date" : ISODate("2015-03-06T18:02:18.544Z"),
"__v" : 0
}


I don't understand why the console.log(els) return [], because there is elements in table. I've tried whith {type: Sting} but nothing at all.


Thanks


Aucun commentaire:

Enregistrer un commentaire