在mongodb php中查询数组内部的值并更新(索引未知)?

时间:2012-09-14 12:41:19

标签: php mongodb

我想查询数组中的特定值并更新它,我不知道索引。以下是内容。

{ "_id" : ObjectId("50072b17b4a6de3b1100000f")
"employment_details" : [
 {
     "_id" : ObjectId("50072b17b4a6de3b11000015"),
     "title" : "Information Technology Compliance & Security",
     "rank" : null,
     "department" : null,
     "current" : false,
     "company_id" : ObjectId("5007269fb4a6de941001d19d")
 }
......
{
     "_id" : ObjectId("50072b17b4a6de3b11000018"),
     "title" : "security engineer",
     "rank" : null,
     "department" : null,
     "current" : false,
     "company_id" : ObjectId("5007269fb4a6de941001dasd")
 }
{
     "_id" : ObjectId("50072b17b4a6de3b11000016"),
     "title" : "software Engineer",
     "rank" : null,
     "department" : null,
     "current" : true,
     "company_id" : ObjectId("5007269fb4a6de94100189e")
}  
]

如果 _id 匹配<我想更改 employment_details 中数组内特定对象的特定当前字段(我不知道索引) strong> ObjectId(“50072b17b4a6de3b1100000f”)和 company_id 匹配 ObjectId(“5007269fb4a6de94100189e”)

这就是我所做的。但不是更新。

$criteria = array("_id" => $mongo_id, "employment_details.company_id" => $company_id);
$new_object = array('$set' => array('employment_details.$.current' => "false", "updated_at" => $time));
$mycollection->update($criteria,$new_object);

如何进行此类更新?

0 个答案:

没有答案