我知道之前问过这个问题,但我希望有人可以帮助我。我使用meteorchef的基本模板。
从ui / containers目录中的ScoreTotal.js开始:
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);
在我的服务器/出版物中:
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;
});
当我在console.log中看到结果时,我看到聚合有效,但是我得到了错误" Publish函数返回了一个非游标数组"
感谢帮助!
答案 0 :(得分:1)
您可能想要使用某种方法。
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.
})