Hello,
I’m trying to update ‘odometer’ value for on my collection:
Cars = new Mongo.Collection('cars');
It has the following structure
addCar: function(carNum, regDate, mark, model, consump, fuelCost, owner, odometer){
if(!Meteor.userId()){
throw new Meteor.Error('No access: You are not logged in.');
}
Cars.insert({
userId: Meteor.userId(),
owner: owner,
createdAt: new Date(),
carNum: carNum,
fuelCost: fuelCost,
regDate: regDate,
mark: mark,
model: model,
odometer: odometer,
consump: consump
});
I also have a different Collection called Trips,
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
});
},
What I’m trying to do is
- I want to add a trip, with written by me distance.
- When I added the distance, it reads the car’s odometer value and sums it with the distance value, adding both to the addTrip, so I know that for that trip I had the following odometer value, and following distance travelled, and when I look at Cars collection I see that the odometer value for the used recently car is updated.
- I want to update the car’s odometer value, but I guess I can’t use elementId, I need to find it via value named car (Trips) and carNum (Cars).
updateOdometer: function(elementId, value){
if(!Meteor.userId()){
throw new Meteor.Error('No access: You are not logged in.');
}
Cars.update(elementId, {
$set: { odometer: value },
});
},
- I need to remove the distance travelled upon Trip removal
Here’s what I have right now
delTrip: function(tripId){
Trips.remove(tripId);
}