MongoDB set $ inc limit

I have a database of sports players that contains their "skills." For example, a soccer player in the database has 14 skills. Every day I imitate the training of their skill so prepared that the day is increased by a certain amount. My collection has over 1.5 million entries, so I am doing a massive update. The problem is that using $ inc, it can set the limit, in my case the skill limit is 100. How can I set the limit on the field, so it won’t be updated anymore if it exceeds the limit?

I also tried to β€œfix” the skills after the update, I mean that after training the simulation, I run a script that iterates all the players, and if it has a field with an exceeded value, I make an update request to fix it. but making 1.5 million separate requests kills the server, just as there are other ways to do this?

Edit: The increased value has some random values ​​in the calculations, so this is not the same for all players. But the value can be from 0 to 1, rounded up to the 2nd category, for example, it can be 0.1, 0.2, 0.3 .... 1. Thus, I group players with this value and trained skill and I am updating the database using the $ in operator, which contains the identifiers of players who train the same skill, and their training value is the same.

+3
source share
1 answer

You can limit it to a request document:

db.players.update({skills : {$lt : 100}}, {$inc : {skills : 1}})

+7
source

All Articles