【问题标题】:How to insert an array into a mongodb collection as a separate document using codeigniter如何使用 codeigniter 将数组作为单独的文档插入到 mongodb 集合中
【发布时间】:2023-04-09 13:58:01
【问题描述】:

我是 mongoDB 的新手。现在我在将数组插入 mongoDB 集合时遇到了一些麻烦。我希望它保存为单独的文档。例如我有一个像下面这样的数组:

 $aa = Array
 (
     [0] => Array
     ( 
        [id] => 1
        [name] => AA, BB & CC
        [colour] => 2
     )

     [1] => Array
     (
        [id] => 2
        [name] => DD
        [colour] => 3
     )
)

现在我想将它插入/更新/推送到一个集合中,比如说测试,我想将它保存为每个文档的单独文档。我将 Alex Bilbie 的库与我的 codeigniter 一起使用。

提前非常感谢。

【问题讨论】:

    标签: php arrays codeigniter mongodb insertion


    【解决方案1】:

    嗯,这是一个非常简单的解决方案。

    MongoCollection::batchInsert ( 数组 $a [, 数组 $options = array() ] )

    这解决了我的问题。

    http://php.net/manual/en/mongocollection.batchinsert.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-02
      • 1970-01-01
      • 2016-09-22
      • 2021-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多