Meteor publish undefined或Publish函数只能返回Cursor或Cursors数组

Alm*_*ren 9 javascript meteor

我的Meteor发布时出现了一些有线问题,当我有findOne它可以工作,但发现它没有和findOne我得到一个游标错误.

这是我的代码

Meteor.publish('organizations', function() {
    var user = Meteor.users.findOne(this.userId);
    if(!user) return '';
     var debugTest = Organizations.findOne(user.organizationId);
      console.log(debugTest._id);
    //return Organizations.findOne({_id: user.organizationId});
}); 
Run Code Online (Sandbox Code Playgroud)

为此,我得到了不确定

如果我做以下事情

Meteor.publish('organizations', function() {
  var user = Meteor.users.findOne(this.userId);
  if(!user) return '';
  console.log(user.organizationId);
  var debugTest = Organizations.findOne(user.organizationId);
  console.log(debugTest._id);
  //return Organizations.findOne({_id: user.organizationId});
});
Run Code Online (Sandbox Code Playgroud)

我找回了两个ID但是返回时我得到以下错误

我是NvoF9MimZ6tJ95c3m NvoF9MimZ6tJ95c3m

来自子KLnQphHTXmQcjEi2D的错误异常错误:发布函数只能返回Cursor或Cursors数组

Chr*_*lin 12

findOne不返回Mongo游标.它返回一个Mongo文档.如果您希望这样做,请尝试更改为使用return Organizations.find({_id: user.organizationId});.这将返回单个文档光标,这是发布调用所期望的.

有关更多信息,请查看文档.