Meteor publish undefined or Publish function can only return a Cursor or an array of Cursors

后端 未结 2 1496
攒了一身酷
攒了一身酷 2021-01-02 09:44

Having some wired issues with my Meteor publish when I have findOne it works but with find it does not and with findOne I get a cursor error.

Here is my code

相关标签:
2条回答
  • 2021-01-02 09:53

    findOne does not return a Mongo cursor. It returns a Mongo document. If you want this to work, try changing to using return Organizations.find({_id: user.organizationId}); instead. That will return a single document cursor which is what the publish call expects.

    For more info check out the docs.

    0 讨论(0)
  • 2021-01-02 10:05

    So the issue was due to my template the pub/sub was working fine but in my template helper I had the following which was causing the issue.

    hasOrganization: function() {
        var user = Meteor.user();
        var organizationsCount = Organizations.find({$or:[{userId: user._id},{**userId**: user.organizationId}]}).count();
        console.log(organizationsCount);
    
        if (organizationsCount >= 1) {
          return true
        } else {
          return false
        }
    

    Here is the fixed version

    hasOrganization: function() {
        var organizationsCount = Organizations.find().count();
        if (organizationsCount >= 1) {
          return true
        } else {
          return false
        }
      }
    
    0 讨论(0)
提交回复
热议问题