I have a document structured like this:
{
"_id" : ObjectId("555d93b52804d78810c20867"),
"username" : "my user",
"myClub" : {
"myPlayers" : [
{
"_id" : ObjectId("555d93b52804d78810c20868"),
"skill" : 55,
"stamina" : 50,
"moral" : 100,
"pos" : null,
},
{
"_id" : ObjectId("555d93b52804d78810c20868"),
"skill" : 55,
"stamina" : 50,
"moral" : 100,
"pos" : null,
},
...
I want to do an update like this:
i have 5 documents like this, i want to update the number 55 in skill to 60 (add plus 5 to the current number) in all "myPlayers" array, but with the following conditions:
I want the max number to update to be 100 and only for those who have the pos to be null, which means if i have this:
"_id" : ObjectId("555d93b52804d78810c20868"),
"skill" : 100,
"stamina" : 50,
"moral" : 100,
"pos" : null
I dont want a plus 5 on it.
What is the code i need to apply to handle this? I have something almost similar when i want to add object to all my documents:
this.model('User').update({},{ '$push': { 'myClub.myPlayers': {another user obj here }}},{multi:true ,upsert:true},function(err,numEffected){
console.log('addPlayer, numEffected:',numEffected);
});
Is it something similar to that one?