Mongodb Meteor.publish 2 mongo查询结果是否在同一出版物下?
我有以下出版物数据:Mongodb Meteor.publish 2 mongo查询结果是否在同一出版物下?,mongodb,meteor,Mongodb,Meteor,我有以下出版物数据: Meteor.publish('privateMessages', function (id) { check(id, String); return Messages.find({private: true, contextId: this.userId, authorId: id}); }); 我还需要这份出版物: Messages.find({private: true, contextId: id, authorId: this.userId});
Meteor.publish('privateMessages', function (id) {
check(id, String);
return Messages.find({private: true, contextId: this.userId, authorId: id});
});
我还需要这份出版物:
Messages.find({private: true, contextId: id, authorId: this.userId});
如何在同一发布下发布两组查询结果?通过返回集合数组来发布多个集合中的文档。查找结果:
Meteor.publish("privateMessages", function (id) {
check(id, String);
return [
Messages.find({private: true, contextId: this.userId, authorId: id}),
Messages.find({private: true, contextId: id, authorId: this.userId})
];
});
注意:以前的版本(即0.7.1.2)要求您在阵列中具有不同的集合
如果在一个数组中返回多个游标,则它们当前必须全部为
来自不同的收藏。我们希望在短期内取消这一限制
未来版本
要克服此限制,您可以使用软件包,也可以在发布中使用“this.added”、“this.removed”和“this.changed”(如建议的那样)来管理游标。您可以使用:
返回Messages.find({$or:[selector1,selector2]})
发布函数为集合返回了多个游标。用户认为不允许在meteor@2paws,这是允许的。请看第二个奇怪的例子,因为如果它返回两个查询,每个查询不同的集合,它就会工作。但如果我像你说的那样做(这就是我想要的),它会说“错误:发布函数为收集消息返回了多个游标”@2paws你有什么版本的Meteor?@2paws,它似乎在新版本中得到了解决。我为您的版本添加了几个解决方案。