Got the following structure for the Collection
addTrip: function(day, month, year, car, a, b, dist, cost, comment){
if(!Meteor.userId()){
throw new Meteor.Error('No access: You are not logged in.');
}
Trips.insert({
userId: Meteor.userId(),
createdAt: new Date(),
day: day,
month: month,
year: year,
car: car,
a: a,
b: b,
dist: dist,
cost: cost,
comment: comment
});
},
I need to calculate monthly (month) summary distance (dist) for a certain user, using userId field.
How will the query look like?
var query = Trips.find({ {userId: {$eq: Meteor.userId()}, month: {$eq: monthVariable}}, {fields: dist});
How do I get the sum tho?