I have mongo collection array as below
[_id] => MongoId Object (
[$id] => 7f841cef13cfcdba230019e2
)
[id] => 33
[name] => Adam
[table] => people
I want to add a field count to existing one
[_id] => MongoId Object (
[$id] => 7f841cef13cfcdba230019e2
)
[id] => 33
[name] => Adam
[count] => 0
[table] => people
If count is already set , then update the array.
I have used ‘update’ method, but need to change the all array instead of one field. How I can do this with php ?
If you are asking how to set the
countfield to a given value (and creating the field if not present yet) without changing anything else , you can use the$setoperator: