【发布时间】:2015-07-09 02:19:18
【问题描述】:
如何从 Meteor JS 中的两个 mongodb 集合中连接(或合并或联合) find() 的结果?
我最好希望将它们作为单个游标对象加入,但获取并转换为数组是可以接受的。在以下代码中,我应该使用什么来代替 UNION?注意:我不需要删除重复的元素。一个连接就足够了。
allLocations: function(){
location_set_1 = TableA.find({'loc':{$exists:1}},{loc:1,limit:300});
location_set_2 = TableB.find({'loc':{$exists:1}},{loc:1,limit:300});
combined_location_set = ??UNION??(location_set_1,location_set_2)
return combined_location_set;
}
一个(n 不完整的)解决方案可能如下,但它会返回一个数组。相反,我需要将光标对象返回给 Meteor 中的“助手”:
a=TableA.find()
b=TableB.find()
c=_.extend({},a.fetch(),b.fetch())
// c=[].concat(a.fetch()).concat(b.fetch());
return c;
【问题讨论】:
-
一个(n 不完整的)解决方案可能如下,但它会返回一个数组。我需要将光标对象返回给 Meteor 中的“助手”: a=LocLogger.find() b=MessagesTable.find() c=_.extend({},a.fetch(),b.fetch()) // c=[].concat(a).concat(b);返回 c;
-
对不起,实际上有两个不同的表。我修复了帖子。
-
请edit您的帖子包含您对问题的任何其他信息。避免在 cmets 中添加它,因为它们更难阅读并且更容易删除。
-
谢谢。我更新了帖子。
标签: javascript mongodb meteor mapreduce