I’m a developer using MongoDB.
A server based on node.js is using mongoose.
It increases the score of the person you want, and I’m going to give him 5 points if he’s a man and 10 points if he’s a woman.
let person = await Person.findOne({_id:'66cb30f2f3aaaeb2676f0b81'}); // First call
let score = person.gender == 'female'? 10 : 5;
await Person.findOneAndUpdate({_id:'66cb30f2f3aaaeb2676f0b81'}, {'$inc' : {'score':score}}) // Second call
It works as you wish with the code above.
But, it’s very uncomfortable to have MongoDB work twice, and I think there’s a better alternative.
If MongoDB is on an external server, wasteful traffic twice.
The heart of my question is this.
Can multiple commands be grouped together and called at once?
I look forward to hearing from you.