Osc*_*son 4 php database json mongodb nosql
这一定很简单,但我似乎无法弄明白......假设我有一个集合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"
}
] }
Run Code Online (Sandbox Code Playgroud)
然后我将如何使用MongoDB的PHP驱动程序向集合中此项中的"tasks"数组添加另一个"任务"
Pab*_*blo 14
使用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))
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5974 次 |
| 最近记录: |