Meteor.publish 不是函数

Meteor.publish is not a function

我有一个 publications.js 文件,其中仅包含

Meteor.publish('org', function(_id){
    return Organizations.findOne(_id);
});

当事情呈现时,我在控制台中得到这个:

Uncaught TypeError: Meteor.publish is not a function

我在这里错过了什么...我敢肯定这很明显。

您可能不小心 运行 客户端上的代码。您有两个选择:

  1. 将发布代码放在应用程序 /server 目录下的文件中。
  2. 将上面的内容包裹在 if (Meteor.isServer) {} 块中。

(1) 优点是不向客户端传输发布代码。

建议阅读:Structuring your application.

如果文件在根目录下,您需要将其包裹起来:

if ( Meteor.isServer ) { /* ... */ }

Meteor.publish 方法仅存在于服务器上。