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();