javascript - meteor 从出版物中返回空光标

标签 javascript meteor

我的出版物前面有一些中间件:

 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/

相关文章:

javascript - 使用 JavaScript 设置 cookie 并获取 cookie

node.js - Nginx proxy_pass 在端口 80 上不起作用

javascript - d3.js 在 Meteor 中未定义

javascript - 为什么新版本的 jQuery 不能使用这个递归?

javascript - Vanilla JavaScript 在主体上设置样式

javascript - 将 Jquery 添加到 Vue-Cli 3

javascript - 使用 valueOf/toString

javascript - meteor JS : RegisterHelper to display associated user information

javascript - meteor 应用程序无故失败

javascript - mongo find选择器导致返回不匹配的结果