我的出版物前面有一些中间件:
Meteor.publish(publicationIdentifier, function (...args) {
try {
middleware()
} catch(error) {
return Users.find('emptyCursor')
}
return Model.pubsub(...args)
})
当中间件抛出错误时,我需要返回一个空的Cursor。
我目前通过在某个任意集合上使用带有无效ID的find来执行此操作:return Users.find('emptyCursor')
有没有更好的方法呢?
我试过了
return
return false
return null
return new Mongo.Cursor()
答案 0 :(得分:1)
与doc
类似 // 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 [];
}
});