0

I have 1000 users in my mongo db collections, i want to do some updating on them without loading them into the memory, the updating are those:

In every user Object i have the following:

user : {
    money : 100,
    skill : 50,
    stamina : 50
}

I want to do the following simple operations:

 user.skill            = Math.max(0, user.skill + 50);
 user.stamina          = Math.max(0,Math.min(100, user.stamina + 20));
 user.moral              = Math.max(0,Math.min(100, user.moral + 10));

But again, an update like but not to store them in memory, is it even possible doing those kind of checks? (maybe more complicated things?)

totothegreat
  • 1,633
  • 4
  • 27
  • 59

1 Answers1

1

You should have a look at update operators in Mongodb : http://docs.mongodb.org/manual/reference/operator/update/

Those operators are usefull to update fields in documents without loading the document to the client, so it looks appropriate to your case :)

You would need : $inc, $min, $max,

codename44
  • 867
  • 9
  • 19