【发布时间】:2014-11-26 20:03:55
【问题描述】:
我有一种情况,我需要订阅同一个集合两次。我的服务器端代码中的两个发布方法如下:
Meteor.publish("selected_full_mycollection", function (important_id_list) {
check(important_id_list, Match.Any); // should do better check
// this will return the full doc, including a very long array it contains
return MyCollection.find({
important_id: {$in: important_id_list}
});
});
Meteor.publish("all_brief_mycollection", function() {
// this will return all documents, but only the id and first item in the array
return MyCollection.find({}, {fields: {
important_id: 1,
very_long_array: {$slice: 1}
}});
});
我的问题是我在订阅后没有在客户端看到完整的文档。我认为这是因为它们被仅发布简短版本的方法所覆盖。
我不想在不需要长数组时用长数组堵塞我的客户端内存,但我确实希望它们在我需要时可用。
简要版在启动时订阅。当用户访问深入了解更多洞察的模板时,订阅完整版。
我该如何妥善处理这种情况?
【问题讨论】: