如何返回空光标?
Meteor.publish('example', function(id) {
check(id, Match.Maybe(String))
if (!this.userId) return []
})
在此示例中,如果用户未登录,出版物应该给我一个空结果。但是按照上面所示的方式执行会出现错误
Error: Publish function can only return a Cursor or an array of Cursors
最佳答案
您可以告诉订阅者集合已准备就绪,但不提供任何数据,如下所示:
return this.ready();
还有其他选项,例如 stop() 和 error(),具体取决于您希望客户端的行为方式。 Meteor 指南中介绍了它们:
关于javascript - 如何在发布时返回空结果游标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42461267/