我需要使用對象數組中的兩個參數來收集MongoDb集合的元素。MongoDb Collection.find()在查詢中有多個操作符
我使用collectionX.find
類型(),以使只有具有組合這些元素。「services.servicesId:[" 1 "," 3 "," 6 "]
與"services.value": true
,不"services.value" : false
始終返回的所有元素,因爲所有的元素具有‘servicesId’
我試過多種方法,包括使用$符號,但沒有成功,返回一個空數組。我試着用$and
太返回的所有元素。
我使用此代碼發佈在我身上teor客戶:
var servicesIds = ["1", "3", "5"]
return CollectionX.find (
{"services.serviceId": {$in: servicesIds}},
{"services.value": true}
);
對象的結構如下:
Id: "ou5HNQGM2KxbBetmy"
createdAt: Mon Apr 06 2015
otherData: Object
personalData: Object
email: [email protected]
mobilephone: "11-98654-8785"
name: "UserName"
phone: "11-2625-6364"
services: Array [20]
0: Object {
serviceId: "1",
value: true
} ...
你得到了什麼。 ? 'CollectionX.find({'services.serviceId':{$ in:[servicesIds]}});' – Ethaan