我的出版物前面有一些中间件:
Meteor.publish(publicationIdentifier, function (...args) {
try {
middleware()
} catch(error) {
return Users.find('emptyCursor')
}
return Model.pubsub(...args)
})
当中间件抛出错误时,我需要返回一个空的 Cursor。
我目前通过在某个任意集合上使用带有无效 ID 的查找来做到这一点:return Users.find('emptyCursor')
有更好的方法吗?
我试过了
return
return false
return null
return new Mongo.Cursor()
最佳答案
喜欢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 [];
}
});
关于javascript - meteor 从出版物中返回空光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47867373/