将数组深入到文档中

时间:2016-03-05 17:32:58

标签: php mongodb traversal

我有这个文件:

{
"_id" : ObjectId("56db04fcf0aac2042ea63de4"),
"POST_ID" : 3,
"QA" : [
    {
        "Q_ID" : 1,
        "ANSWERS" : [ ]
    },
    {
        "Q_ID" : 2,
        "ANSWERS" : [ ]
    }
]
}

现在我想把$答案推到这个文件中

    $answer = array('A_ID'=>$answer_id, 'ANSWER'=>$_POST['answer'], 'COMMENTS'=>array());

我试过了:

$collection->update(array('POST_ID'=>3),array('$push'=>array('QA.ANSWERS'=>$answer)),false,true);

给了我错误:

 Catchable fatal error: Argument 3 passed to MongoCollection::update() must be of the type array, boolean given, called in /var/www/html/ProjectTest/post.php on line 30 and defined in /var/www/html/ProjectTest/include/Function Helper.php on line 126

我有办法做到这一点吗?

0 个答案:

没有答案