Javascript meteor从发布返回空游标
我的出版物前面有一些中间件:Javascript meteor从发布返回空游标,javascript,meteor,Javascript,Meteor,我的出版物前面有一些中间件: Meteor.publish(publicationIdentifier, function (...args) { try { middleware() } catch(error) { return Users.find('emptyCursor') } return Model.pubsub(...args) }) 当中间件抛出错误时,我需要返回一个空游标。 目前,我通过在某些任意集合上使用id无效的find来
Meteor.publish(publicationIdentifier, function (...args) {
try {
middleware()
} catch(error) {
return Users.find('emptyCursor')
}
return Model.pubsub(...args)
})
当中间件抛出错误时,我需要返回一个空游标。
目前,我通过在某些任意集合上使用id无效的find来实现这一点:returnusers.find('emptyCursor')
有没有更好的办法
我试过了
return
return false
return null
return new Mongo.Cursor()
就像在
我通常只做
this.ready()
,在这样的分支中没有返回语句。
// Sometimes publish a query, sometimes publish nothing.
Meteor.publish('secretData', function () {
if (this.userId === 'superuser') {
return SecretData.find();
} else {
// Declare that no data is being published. If you leave this line out,
// Meteor will never consider the subscription ready because it thinks
// you're using the `added/changed/removed` interface where you have to
// explicitly call `this.ready`.
return [];
}
});