Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Meteor.publish('organizations', function() {
    var user = Meteor.users.findOne(this.userId);
    if(!user) return '';
     var debugTest = Organizations.findOne(user.organizationId);
      console.log(debugTest._id);
    //return Organizations.findOne({_id: user.organizationId});
}); 

For this I get undefined

If I do the following

Meteor.publish('organizations', function() {
  var user = Meteor.users.findOne(this.userId);
  if(!user) return '';
  console.log(user.organizationId);
  var debugTest = Organizations.findOne(user.organizationId);
  console.log(debugTest._id);
  //return Organizations.findOne({_id: user.organizationId});
});

I get back both ID's but with the return I get the following error

Teh I NvoF9MimZ6tJ95c3m NvoF9MimZ6tJ95c3m

The error Exception from sub KLnQphHTXmQcjEi2D Error: Publish function can only return a Cursor or an array of Cursors

like image 720
Almog Avatar asked Dec 16 '14 22:12

Almog


1 Answers

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.

like image 187
Chris Franklin Avatar answered Sep 18 '22 19:09

Chris Franklin