如何在发布时返回一个空的结果光标?

我如何返回一个空的光标?

Meteor.publish('example', function(id) { check(id, Match.Maybe(String)) if (!this.userId) return [] }) 

在这个例子中,如果用户没有login,那么发布应该会给我一个空的结果。但是像上面显示的那样,给了我这个错误

 Error: Publish function can only return a Cursor or an array of Cursors 

您可以告诉订阅者该集合已准备好,但不提供任何数据,如下所示:

 return this.ready(); 

还有其他选项,如stop()和error(),这取决于您希望客户端的行为方式。 他们在meteor指南中被覆盖:

https://docs.meteor.com/api/pubsub.html#Meteor-publish