我有一个包含books array
的文档"_id" : ObjectId("517b80cf9de5ee780b000003"),
"publisher_name" : "ABC",
"books" : [{
"_id" : ObjectId("517b80cf9de5ee780b000000"),
" title" : "<b>AAA</b>",
"published" : 1
}, {
"_id" : ObjectId("517b80cf9de5ee780b000001"),
" title" : "<b>BBB</b>",
"published" : 1
}, {
"_id" : ObjectId("517b80cf9de5ee780b000002"),
" title" : "<b>CCC</b>",
"published" : 1
}],
我想更新“已发布”字段,将其设置为“0”
$theObjId = new MongoId($bookid);
$collection->update(array("_id" => $theObjId ), array('$set' => array('published'=> '0')));
但我使用的查询不会更新它。
答案 0 :(得分:1)
$theObjId = new MongoId($bookid);
$collection->update(array("_id" => $theObjId ), array('$set' => array('books.$.published'=> '0')));