returnsDown: function(studentId) {
var user = Meteor.user();
if (!user)
throw new Meteor.Error(401, "You need to login to upvote");
var student = Students.findOne(studentId);
if (!student)
throw new Meteor.Error(422, 'Student not found');
Students.update(student._id, {
$inc: {
returns: -1
}
});
}
Now this decreases the returns
field by 1. Fine. Is there anything mongodb built in that can prevent the going below 0? In this case, when a field value hits 0, no reduction allowed anymore?
Otherwise, the way I’m thinking of is to check if the field is not 0 before decreasing everything, unless there’s a better way.