Javascript 如何在发布时返回空的结果游标?

Javascript 如何在发布时返回空的结果游标?,javascript,node.js,meteor,Javascript,Node.js,Meteor,如何返回空游标 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 您可以告诉订户集合已准备就

如何返回空游标

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(),具体取决于您希望客户端的行为方式。流星指南中包括了它们: