I have the following code, when I call $set it overwrites my data
with the correct information for the correct user.
works:
$coll1->update(array("_id"=>$pid),array('$set' => array("balance" => $credit)));
However, when I want to increase nothing happens.
does not work:
$coll1->update(array("_id"=>$pid),array('$inc' => array("balance" => $credit)));
Based on the documentation they should follow the same pattern:
$inc
{ $inc : { field : value } }
increments field by the number value if field is present in the object, otherwise sets field to the number value. This can also be used to decrement by using a negative value.
$set
{ $set : { field : value } }
sets field to value. All datatypes are supported with $set.
First off, here’s a quick gist that demonstrates the code working correctly.
There are two things to note.
Try running in “safe” mode to ensure that your updates are working correctly.
In your case this looks as follows: