Hey there! I’m a bit of a noob here, so I apologize in advance if the question is duplicated
What is the criteria for executing logic in the backend server vs doing it in the mongo server?
For example (sorry if the syntax is messed up):
You have user that has withdrawn some funds. To update their data you can either
const withdrawFunds = (userId, amount) => {
const user = User.getById(userId)
// option 1: Logic is executed by the backend server
const currentFunds = user.funds - amount
User.updateOne({_id: userId}, {$set: {funds: amount}})
// option 2: Logic is executed by the mongo server
User.updateOne({_id: userId}, {$set: {funds: { $inc: -amount}} )
}
Is one option generally more performant than the other, or does it depend on the servers being used?
Are there any rules of thumb for these types of situations?