0
的陣列匹配流星集合假設我有我的ID想要篩選集合的列表:基於價值觀
const ids = [1, 2, 3, 4];
如何過濾收集到只匹配這些ID?像這樣的東西不起作用:
return Coll.fetch({_id: {$all: ids}});
的陣列匹配流星集合假設我有我的ID想要篩選集合的列表:基於價值觀
const ids = [1, 2, 3, 4];
如何過濾收集到只匹配這些ID?像這樣的東西不起作用:
return Coll.fetch({_id: {$all: ids}});
下面是我可能會接近這個:
function hasAllIds(collections, ids) {
for (let i = 0; i < collections.length; i++) {
let count = collections[i].find({
_id: {
$in: ids
}
}).count();
if (count === ids.length) {
return collections[i];
}
}
return null;
}
const colls = [Meteor.users, Games]; //etc.
const ids = [1, 2, 3];
const coll = hasAllIds(colls, ids);
if (coll) {
coll.find(); //or whatever
}
這將工作:
return Collection.find({_id: {$in: ids}}).fetch();