比较来自世界各地的卖家的域名和 IT 服务价格

MongoDB 在 PHP - 如何将元素插入集合中的数组?

它应该很容易,但我似乎不明白......假设我有一个集合
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"
}
] }


像驾驶员一样 PHP 为了 MongoDB 然后我会去添加另一个 "task" 掩码 "tasks" 在此元素集合中
已邀请:

石油百科

赞同来自:

使用Montgo操作
$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//
/;

要回复问题请先登录注册