Aggregation not working when deployed in meteor.com

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();
});

You mentioned the console, but did you try the meteor logs command to see if something wrong happened server-side?

I’v tried but it’s asking me for a username and password, and no matter what I put it says: Couldn’t view logs: login failed.

Also tried to login first using meteor login but yet the same login failure.

Sorry finally I could see logs, I wasn’t using the --email argument…

However, nothing more that a bunch of these appear, no errors whatsoever:

[Mon Jun 29 2015 10:34:34 GMT+0000 (UTC)] INFO HIT /client/templates/login/login.js?b77bb4873b9f3eda15f56f4acf68327992afdc8e 88.29.110.70
[Mon Jun 29 2015 10:34:34 GMT+0000 (UTC)] INFO HIT /client/templates/login/loginBridge.js?a92e5091864adc3590eb12da95911160647639d0 88.29.110.70
[Mon Jun 29 2015 10:34:34 GMT+0000 (UTC)] INFO HIT /client/templates/profile/profile.js?6578b5445569846801ded584753a3062f4e97656 88.29.110.70
[Mon Jun 29 2015 10:34:34 GMT+0000 (UTC)] INFO HIT /client/templates/global_helpers.js?889fff245af88747cc9623774499f036cb1e65d0 88.29.110.70
[Mon Jun 29 2015 10:34:35 GMT+0000 (UTC)] INFO HIT /client/templates/index/main.js?a76229b09a92073aaf2835968d4d7b50c9c16a00 88.29.110.70
[Mon Jun 29 2015 10:34:35 GMT+0000 (UTC)] INFO HIT /packages/262da6fb1e9c97be84333c429c9a2929c80f8e3b.map 88.29.110.70

For some reason this pipeline does not work in Meteor’s mongo version 2.6, mine is on 3.0 and that’s why it’s working only on my local server :confused:

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']}, //<-- This does not work on 2.6 MongoDB
			//partidos: {$sum: 1}
			partidos: {$push:'$$ROOT'} 
		}},
		{$sort: {'_id':1}}
	];
1 Like

Clearly off the topic but mongo has many useful aggregation operators (docs).

{$match: {date: {$gte: new Date}}},
{$group: {
    _id: {
        y: {$year: '$date'},
        m: {$month: '$date'},
        d: {$dayOfMonth: '$date'}},
    partidos: {$push: '$$ROOT'}}},
{$sort: {'_id': 1}}

if you’re using MongoDB 3.0.

{$match: {date: {$gte: new Date}}},
{$group: {
    _id: {$dateToString: {format: '%Y%m%d', date: '$date'}},
    partidos: {$push: '$$ROOT'}}},
{$sort: {'_id': 1}}

Thank you for that mnmtanish, always useful see better coding than your own!.