I have a document like this (this is very simplified):
{
'name' : 'test',
'age' : 16
}
and also this
{
'name' : 'test2'
}
I want to set all 'age' to 14 if it does not exist.
How can I do this?
Try the $exists
operator:
$this->mongolib->update('people', array('age' => array('$exists' => false)), array('$set' => array('age' => 14)), array('upsert' => true, 'multiple' => true));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With