<i id='emVaj'><tr id='emVaj'><dt id='emVaj'><q id='emVaj'><span id='emVaj'><b id='emVaj'><form id='emVaj'><ins id='emVaj'></ins><ul id='emVaj'></ul><sub id='emVaj'></sub></form><legend id='emVaj'></legend><bdo id='emVaj'><pre id='emVaj'><center id='emVaj'></center></pre></bdo></b><th id='emVaj'></th></span></q></dt></tr></i><div id='emVaj'><tfoot id='emVaj'></tfoot><dl id='emVaj'><fieldset id='emVaj'></fieldset></dl></div>
<legend id='emVaj'><style id='emVaj'><dir id='emVaj'><q id='emVaj'></q></dir></style></legend>
  • <tfoot id='emVaj'></tfoot>

      <small id='emVaj'></small><noframes id='emVaj'>

        <bdo id='emVaj'></bdo><ul id='emVaj'></ul>

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

        时间:2024-04-12

      1. <small id='0ncAA'></small><noframes id='0ncAA'>

          <tbody id='0ncAA'></tbody>

        • <legend id='0ncAA'><style id='0ncAA'><dir id='0ncAA'><q id='0ncAA'></q></dir></style></legend>

            • <tfoot id='0ncAA'></tfoot>
              <i id='0ncAA'><tr id='0ncAA'><dt id='0ncAA'><q id='0ncAA'><span id='0ncAA'><b id='0ncAA'><form id='0ncAA'><ins id='0ncAA'></ins><ul id='0ncAA'></ul><sub id='0ncAA'></sub></form><legend id='0ncAA'></legend><bdo id='0ncAA'><pre id='0ncAA'><center id='0ncAA'></center></pre></bdo></b><th id='0ncAA'></th></span></q></dt></tr></i><div id='0ncAA'><tfoot id='0ncAA'></tfoot><dl id='0ncAA'><fieldset id='0ncAA'></fieldset></dl></div>
                • <bdo id='0ncAA'></bdo><ul id='0ncAA'></ul>
                • 本文介绍了PHP中的MongoDB - 如何将项目插入集合中的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这一定很简单,但我似乎无法弄清楚...假设我有一个集合 users,这是集合中的第一项:

                  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" : "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 驱动程序将另一个任务"添加到集合中此项的任务"数组中

                  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

                  推荐答案

                  使用Mongo的$push操作:

                  Use Mongo's $push operation:

                  $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))
                  );
                  

                  这篇关于PHP中的MongoDB - 如何将项目插入集合中的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:需要一个带有 php 的 DynamoDB 的完整示例 下一篇:无法通过 PHP 连接到 MongoDB

                  相关文章

                • <legend id='iLItn'><style id='iLItn'><dir id='iLItn'><q id='iLItn'></q></dir></style></legend>

                  <tfoot id='iLItn'></tfoot>

                  1. <small id='iLItn'></small><noframes id='iLItn'>

                      <bdo id='iLItn'></bdo><ul id='iLItn'></ul>

                      <i id='iLItn'><tr id='iLItn'><dt id='iLItn'><q id='iLItn'><span id='iLItn'><b id='iLItn'><form id='iLItn'><ins id='iLItn'></ins><ul id='iLItn'></ul><sub id='iLItn'></sub></form><legend id='iLItn'></legend><bdo id='iLItn'><pre id='iLItn'><center id='iLItn'></center></pre></bdo></b><th id='iLItn'></th></span></q></dt></tr></i><div id='iLItn'><tfoot id='iLItn'></tfoot><dl id='iLItn'><fieldset id='iLItn'></fieldset></dl></div>