我可以将订阅存储在名称与服务器不同的集合中

时间:2013-06-25 08:13:59

标签: meteor

有没有办法在不同的minimongo集合中存储同一服务器集合的订阅?

如果没有最佳做法可以解决?

我的汇总表中有50k数据集,文档中有很多细节。

// Server
var collection = new Meteor.Collection("collection");
Meteor.publish("detail", function (id) {
   return collection.find({_id: id});
});
// A pager that does not include the data (fields:{data:0})
Meteor.publish("master", function (filter, sort, skip, limit) {
   return collection.find({name: new RegExp("^" + filter + "|\\s" + filter, "i")},
                          {limit: limit, 
                           skip: skip, 
                           sort: options, 
                           fields: {data: 0}
                          });
});

// Client
var collection = new Meteor.Collection("collection");
Deps.autorun(function () {
  Meteor.subscribe("master",
      Session.get("search"),
      Session.get("sort"),
      Session.get("skip"),
      Session.get("limit")
  );
  Meteor.subscribe("detail", Session.get("selection"));
});

上面的问题:两个订阅都被输入到同一个集合中。

如果查找结果存储在同一本地集合中,则此方法无效。

拥有一个包含订阅/发布名称的本地集合会很棒。

// Client
var detail = new Meteor.Collection("detail"),
   master = new Meteor.Collection("master");

任何想法如何鼓励订阅使用我自己的收藏品?

1 个答案:

答案 0 :(得分:1)

我通过Andrews Hint的帮助找到了解决方案 Discover Meteor 一书,其中显示了许多发布订阅方案。

无论如何:阅读后我发现我前往的问题也在Meteor文档Meteor.publish

中得到了回答。

最后一个示例基本上为“messages”集合创建了一个虚拟集合“counts”。干得好; - )

“Wer lesen kann ist im Vorteil!”

相关问题