Hello,
I’m trying to get a list of users and their trip milleage summary.
For list users I am using Meteor.users and for their trips I have a mongo.db collection called ‘Trips’
The output should be something like (example) :
const data = [[“Igor L”, 6360],
[“Aleksei D”, 836]];
So far my query looks like:
const query = Meteor.users.find().fetch();
const trips = query.map(function(o){
let tripDist = Trips.findOne({"userId": {$eq: o.profile._id}}, {fields: {dist:1}, limit:1}).dist;
console.log(tripDist);
return [o.profile.name_first+" "+o.profile.name_last, tripDist];
});
I do the get profile.name_first & profile.name_last, but I cannot perform the search using the $eq: o.profile._id.
How do I do that?
Here’s my Trips collection:
addTrip: function(day, month, year, car, a, b, dist, cost, odometer, 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,
odometer: odometer,
car: car,
a: a,
b: b,
dist: dist,
cost: cost,
comment: comment
});
//Roles.setUserRoles(Meteor.userId(), 'admin');
},