Cas
Cas

Reputation: 1

Publish returns an array of non-cursors

I know the question was asked here before, still I hope someone can help me out. I work with the base template of meteorchef.

From the ScoreTotal.js in the ui/containers directory I do:

const composer = (params, onData) => {
   const subscription = Meteor.subscribe('teams.scores');
   if (subscription.ready()) {
    const teams = Teams.find().fetch(); 
    onData(null, { teams });
  }
};
export default composeWithTracker(composer, Loading)(ScoreTotal);

In the server/publications I have:

Meteor.publish('teams.scores', (_id) => {
    var pipeline = [
        {$project: 
          { _id: 0, 
            teamname: 1, 
            score1: 1,
            score2: 1,
            scoretotal: { $add: [ "$score1", "$score2" ] },
        }}
    ];

    var result = Teams.aggregate(pipeline, {_id});
    return result;
  });

When I console.log the result I see the aggregate works but I get the error "Publish function returned an array of Non-Cursors"

Appreciate the help!

Upvotes: 0

Views: 778

Answers (1)

Afif Sohaili
Afif Sohaili

Reputation: 246

you might wanna use a method instead.

Meteor.methods({
  'teams.scores': function(_id) {
    var pipeline = [
      {
        $project:
        { _id: 0,
          teamname: 1,
          score1: 1,
          score2: 1,
          scoretotal: { $add: [ "$score1", "$score2" ] },
        }
      }
    ]
    var result = Teams.aggregate(pipeline, {_id})
    return result
  }
})

// on client
Meteor.call('teams.scores', function(error, result) {
  // use result to update dom, etc.
})

Upvotes: 1

Related Questions