Hello, I have this publication working on my local server, however when I deploy this to meteor.com nothing is retrieved although there is data in my mongo database that will fit the query.
I don’t get any visible error in my console, any help is appreciated.
Meteor.publish('matchesByDay', function(){
var subscription = this;
var initiated = false;
var partidos = {};
var db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
var pipeline = [
{$match: {date:{$gte:new Date}}},
{$project: {
date: '$date',
day: {$substr: ['$date', 0, 4]},
month: {$substr: ['$date', 5, 2]},
year: {$substr: ['$date', 8, 2]},
minLevel: '$minLevel'
}},
{$group: {
_id: {$concat: ['$year','$month','$day']},
//partidos: {$sum: 1}
partidos: {$push:'$$ROOT'}
}},
{$sort: {'_id':1}}
];
db.collection('matches').aggregate(
pipeline,
Meteor.bindEnvironment(
function(err, result){
if (!err) {
_.each(result, function(r){
partidos[r._id] = r;
subscription.added('matchesByDay', r._id, {
day: r._id.substr(0,2),
month: r._id.substr(2,2),
year: r._id.substr(4,4),
partidos: r.partidos
}
);
});
} else {
Meteor.Error('subscription_matchesByDay', 'Error retrieving data from aggregation.')
}
}
)
);
var matchesHandle = Matches
.find()
.observeChanges({
added: function(id, fields){
if (!initiated) return;
var fecha = moment(fields.date);
var idFecha = fecha.format('DDMMYYYY');
if (!partidos[idFecha]){
partidos[idFecha] = {_id:idFecha, partidos:0};
}
partidos[idFecha].partidos += 1;
subscription.changed('matchesByDay',
idFecha,
{ day: idFecha.substr(0,2),
month: idFecha.substr(2,2),
year: idFecha.substr(4,4),
partidos: partidos[idFecha].partidos
});
}
});
initiated = true;
subscription.onStop(function(){
matchesHandle.stop();
});
subscription.ready();
});