Meteor 发布未定义或发布函数只能返回一个游标或游标数组 [英] Meteor publish undefined or Publish function can only return a Cursor or an array of Cursors

查看:19
本文介绍了Meteor 发布未定义或发布函数只能返回一个游标或游标数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 findOne 时,我的 Meteor 发布有一些有线问题,但它可以工作,但使用 find 却没有,而使用 findOne 时出现光标错误.

Having some wired issues with my Meteor publish when I have findOne it works but with find it does not and with findOne I get a cursor error.

这是我的代码

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});
}); 

为此我未定义

如果我执行以下操作

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});
});

我取回了两个 ID,但返回时出现以下错误

I get back both ID's but with the return I get the following error

我NvoF9MimZ6tJ95c3mNvoF9MimZ6tJ95c3m

Teh I NvoF9MimZ6tJ95c3m NvoF9MimZ6tJ95c3m

错误来自子 KLnQphHTXmQcjEi2D 的异常错误:发布函数只能返回一个游标或游标数组

The error Exception from sub KLnQphHTXmQcjEi2D Error: Publish function can only return a Cursor or an array of Cursors

推荐答案

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

findOne does not return a Mongo cursor. It returns a Mongo document. If you want this to work, try changing to using return Organizations.find({_id: user.organizationId}); instead. That will return a single document cursor which is what the publish call expects.

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

For more info check out the docs.

这篇关于Meteor 发布未定义或发布函数只能返回一个游标或游标数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆