I have a mongo document which I would like to update:
votes: [{
name: 'Bugs Bunny',
percentage: 50
}, {
name: 'Mickey Mouse',
percentage: 49
}]
I want to make sure that the sum of percentage will never exceed 100, when updating an object in the array or adding a new object to the array.
I am wondering is there a way to preview updates and then save them?
Or is there a way to rollback to the previous document when percentage > 100?
I've read I can't use validators: How validate $push in update request mongoose?