Meteor publication error - Publish function returned an array of non-Cursors

Hi!

I have this publication:

publish:

Meteor.publish(‘followings’, function () {
var user_id = this.userId;
if (!user_id) {
this.ready();
return;
}
var user = Meteor.users.findOne({"_id": user_id});
return Meteor.call(“userFounds”, user.followed);
});

methods:

‘userFounds’: function(followeds){
var result = [];
followeds.forEach(function(row){
result[0] =(Meteor.users.findOne({"_id": row}));
console.log(result);
});
return result;
}

route:

Router.route(’/me/following’, function () {
this.render(‘viewFollowing’);
}, {
name: “following”,
onBeforeAction: function (pause) {
if (!Meteor.user()) {
this.render(‘login’);
} else {
this.render(‘viewFollowing’);
}
},
waitOn: function () {
return subs.subscribe(‘followings’);
},
before: filters.isLogued
});

But I am getting this error:
Exception from sub followings id EtfhiC3w2RQKWmu2b Error: Publish function returned an array of non-Cursors.

What are you trying to accomplish with the ‘userFounds’ function? It looks as if you are overwriting the first element of the result array as you iterate over followeds. Additionally, ‘userFounds’ returns an array which means your ‘followings’ publish would return an array.

Publications must return a cursor or an array of cursors.

A cursor is the result of a find(), but not of a findOne() (returns an object) or method call (returns arbitrary EJSONable data).

It looks like you have a modified Meteor.users document which contains an array:

followed: [ userId1, userId2, userId3, ...]

And you want your publication to return the user documents for each userId in the followed array?

2 Likes

Hi ! Thanks for you response.

Yes, I want return the user for each userId in the followed array.I want use smeevil:reactive-block-grid ->

 <div class="row isotope">
       {{> reactiveBlockGrid cursor=followeds template='followingUser' transitionDuration='0.5s' gutter=30 columnWidth=328}}
 </div>