PHP 中的 MongoDB - 如何将项目插入集合中的数组中?
这必须很简单,但我似乎无法弄清楚...假设我有一个集合users
,这是集合中的第一项:
{
"_id" : ObjectId("4d8653c027d02a6437bc89ca"),
"name" : "Oscar Godson",
"email" : "[email protected]",
"password" : "xxxxxx",
"tasks" : [
{
"task" : "pick up stuff",
"comment" : "the one stuff over there"
},
{
"task" : "do more stuff",
"comment" : "lots and lots of stuff"
}
] }
How with the PHP driver for MongoDB然后我会去将另一个“任务”添加到集合中此项的“任务”数组中吗
This has to be easy, but i can't seem to figure it out... Let say i had a collection users
and this is the first item in the collection:
{
"_id" : ObjectId("4d8653c027d02a6437bc89ca"),
"name" : "Oscar Godson",
"email" : "[email protected]",
"password" : "xxxxxx",
"tasks" : [
{
"task" : "pick up stuff",
"comment" : "the one stuff over there"
},
{
"task" : "do more stuff",
"comment" : "lots and lots of stuff"
}
] }
How with the PHP driver for MongoDB would I then go and add another "task" to the "tasks" array in this item in a collection
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用Mongo的
$push
操作:Use Mongo's
$push
operation: