Is it possible to use multipule modifier operations within a single update in PHP with MongoDB?
For example, if I created the following document:
$doc = array(
'one' => 1,
'tags' => array(),
);
And then wanted to add another field ('new') and add an element to the 'tags' array, I could use the following two lines:
$collection->updat开发者_运维技巧e(array('_id'=>$doc['_id']), array('$set' => array('new'=>'value')));
and
$collection->update(array("_id" => $doc['_id']), array('$addToSet' => array('tags'=>'my tag')));
Does anyone know it's possible to do both of these two operations in one 'update' command?
Thanks, Neil
I haven't used mongo in a while, but I believe you should be able to:
$collection->update(array('_id'=>$doc['_id']), array(
'$set' => array('new'=>'value'),
'$addToSet' => array('tags'=>'my tag')
));
精彩评论