使用一个更新查询设置多个字段 [英] Set multiple fields with one update query

查看:100
本文介绍了使用一个更新查询设置多个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码应该可以工作.我本可以错过一些东西,但是现在我将其作为2条单独的更新语句,并决定在这里询问为什么此行不起作用.

The following code should work. I could have missed something, but right now I have it as 2 separate update statements and have decided to ask here why this line isn't working.

$this->db->settings->update(array('_id' => $mongoID),
  array(
    '$set' => array('about' => $about),
    '$set' => array('avatar' => $avatar)
  )
);

阅读指南时我是否错过了某些东西?还是只能使用单独的更新语句?

Did I miss something when reading guides or is it only possible to do with separate update statements?

推荐答案

MongoCollection::update 是更新操作的选项数组.

The third argument to MongoCollection::update is an array of options for the update operation.

$this->db->settings->update(
    array('_id' => $mongoID),
    array('$set' => array('about' => $about, 'avatar' => $avatar))
);

这篇关于使用一个更新查询设置多个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆