开发者

Using multiple modifier operations in a single update in PHP with MongoDB?

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')
));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜