我想查询数组中的特定值并更新它,但我不知道索引。以下是内容。
{ "_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匹配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);
如何进行这样的更新?