I am using MONGOHQ and NODE.JS to make an application, I would really like the help of someone because I have a big problem, I tried everything and look everywhere, so this is my last option.
I have this query on a node JS post:
{ propertyId: '53f4f097f28c16cf87a15664' }
This query is being used here :
db.collection('animal').find(req.body.query).toArray(function (err, animals) {
res.send(
(err === null) ? { status: 'ok', result: animals } : { status: err }
);
});
And its working FINE !
Now the problem :
What I want is to add another query to the find, without modifying the req.body.query.
What I have is a list of _id (not ObjectIds), called myArray, and it's like :
[ '12312123' , '78787878' ]
So I am doing this :
db.collection('animal').find({ $and : [ req.body.query, { '_id' : { $in : myArray} } ] }).toArray(function (err, animals) {
res.send(
(err === null) ? { status: 'ok', result: animals } : { status: err }
);
});
And its giving me an empty list.
But instead, if I do the same query on mongohq like :
find({$and : [ { propertyId: '53f4f097f28c16cf87a15664' }, { '_id' : { $in :['12312123', '78787878']} } ] })
Its giving me a list with 1 element that matches the criteria:
{
_id: "12312123",
propertyId: "53f4f097f28c16cf87a15664",
active: "true"
}
Does anyone have an idea ? I would be glad to hear !
Thanks
Michael