2013-04-27 83 views
0

我有一个包含书籍阵列为什么此查询不更新mongodb字段值?

"_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'))); 

但是我用查询不更新的文件。

回答

1

我解决了。我应该使用$位置运算符。

$theObjId = new MongoId($bookid); 
$collection->update(array("_id" => $theObjId), array('$set' => array('books.$.published'=> '0')));