PHP中的MongoDB-如何将项插入集合中的数组?

PHP中的MongoDB-如何将项插入集合中的数组?,php,json,mongodb,database,nosql,Php,Json,Mongodb,Database,Nosql,这一定很容易,但我似乎不明白。。。假设我有一个集合users,这是集合中的第一项: { "_id" : ObjectId("4d8653c027d02a6437bc89ca"), "name" : "Oscar Godson", "email" : "oscargodson@xxx.com", "password" : "xxxxxx", "tasks" : [ { "task" : "pick up stuff",

这一定很容易,但我似乎不明白。。。假设我有一个集合
users
,这是集合中的第一项:

{ 
    "_id" : ObjectId("4d8653c027d02a6437bc89ca"), 
    "name" : "Oscar Godson", 
    "email" : "oscargodson@xxx.com", 
    "password" : "xxxxxx", 
    "tasks" : [
    {
        "task" : "pick up stuff",
        "comment" : "the one stuff over there"
    },
    {
        "task" : "do more stuff",
        "comment" : "lots and lots of stuff"
    }
] }

如何使用用于MongoDB的PHP驱动程序,然后将另一个“任务”添加到集合中此项的“任务”数组中

使用Mongo的
$push
操作:

$new_task = array(
  "task" => "do even more stuff",
  "comment" => "this is the new task added"
);
$collection->update(
  array("_id" => ObjectId("4d8653c027d02a6437bc89ca")), 
  array('$push' => array("tasks" => $new_task))
);

正是我要找的!谢谢。问题应该是。。。如何将项目添加到现有文档中的数组中?插入带有数组的文档不是使用$push完成的,因为$push是一个更新操作符。您知道新版本的php MongoDB API是如何做到这一点的吗?