当我有 findOne 时,我的 Meteor 发布有一些有线问题,它可以工作,但使用 find 时它不起作用,使用 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});
});
为此我得到了 undefined
如果我执行以下操作
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,但返回时出现以下错误
我 NvoF9MimZ6tJ95c3m NvoF9MimZ6tJ95c3m
错误 子 KLnQphHTXmQcjEi2D 错误的异常:发布函数只能返回一个 Cursor 或一个 Cursors 数组
最佳答案
findOne
不返回 Mongo 游标。它返回一个 Mongo 文档。如果您希望它起作用,请尝试改为使用 return Organizations.find({_id: user.organizationId});
。这将返回发布调用所期望的单个文档游标。
有关更多信息,请查看 docs .
关于javascript - Meteor publish undefined 或 Publish 函数只能返回一个 Cursor 或一个 Cursors 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27515309/