本文介绍了Meteor publish undefined或Publish函数只能返回Cursor或Cursors数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Meteor发布有一些有线问题,当我有findOne时它可以工作,但发现它没有,并且与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

Teh I
NvoF9MimZ6tJ95c3m
NvoF9MimZ6tJ95c3m

Teh INvoF9MimZ6tJ95c3mNvoF9MimZ6tJ95c3m

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

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

推荐答案

findOne 不返回一个Mongo游标。它返回一个Mongo文档。如果您希望这样做,请尝试更改为使用返回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 publish undefined或Publish函数只能返回Cursor或Cursors数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 17:56