Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 流星如何避免发布所有_Meteor - Fatal编程技术网

Meteor 流星如何避免发布所有

Meteor 流星如何避免发布所有,meteor,Meteor,我以为我了解Meteor中的酒吧/酒吧,直到我遇到这个问题 假设您有许多供公众使用的博客条目,并且用户导航到/:blogId 你用的是 Blogs.findOne(FlowRouter.getParam('blogId')); 目前,在服务器端,我正在发布所有博客条目 Meteor.publish("blogs", function () { return Blogs.find({}); }); 我猜我应该只发布请求的博客条目,比如: Meteor.publish("blogs",

我以为我了解Meteor中的酒吧/酒吧,直到我遇到这个问题

假设您有许多供公众使用的博客条目,并且用户导航到/:blogId

你用的是

Blogs.findOne(FlowRouter.getParam('blogId'));
目前,在服务器端,我正在发布所有博客条目

Meteor.publish("blogs", function () {
    return Blogs.find({});
});
我猜我应该只发布请求的博客条目,比如:

Meteor.publish("blogs", function (_id) {
    return Blogs.find(_id);
});

这里的最佳做法是什么?

您可以为特定路线制作另一份出版物(仅返回一份)。

您的问题完全正确:

Meteor.publish("oneBlog", function (_id) {
  return Blogs.find(_id); // must return a *cursor* or array of cursors, not an object
});

Meteor.publish("allBlogs", function () {
  return Blogs.find();
});
从客户端根据路由参数订阅
oneBlog

Meteor.subscribe("oneBlog", FlowRouter.getParam('blogId'));

是的,这是我的假设。您实际使用findOne({})吗?您是否在订阅中传递it参数?我们可以看一个例子吗?它是一个包还是一个普通的集合,你创建的?