lundi 6 avril 2015

MongoDb Collection.find() with multiple operators on query

I need to collect elements of a collection of MongoDb using two parameters within a array of an object.


I using collectionX.find type () to bring only those elements that have the combination of "services.servicesId: [" 1 "," 3 "," 6 "] with "services.value": true, without "services.value" : false


Always returns all elements because all elements has the "servicesId" .


I tried several ways, including using the $ sign, but without success, returned an empty array. I tried with $and and returns all elements too.


I am using this code to Publish on Meteor Client:



var servicesIds = ["1", "3", "5"]
return CollectionX.find (
{"services.serviceId": {$in: servicesIds}},
{"services.value": true}
);


The object has the following structure:



Id: "ou5HNQGM2KxbBetmy"
createdAt: Mon Apr 06 2015
otherData: Object
personalData: Object
email: test@gmail.com
mobilephone: "11-98654-8785"
name: "UserName"
phone: "11-2625-6364"
services: Array [20]
0: Object {
serviceId: "1",
value: true
} ...

Aucun commentaire:

Enregistrer un commentaire