Laravel-mongodb: Support for Bulk Write Operations

Created on 22 May 2015  路  2Comments  路  Source: jenssegers/laravel-mongodb

How to do bulk operations provided by Mongo Core Library?

http://docs.mongodb.org/manual/core/bulk-write-operations/

  1. Bulk.insert()
  2. Bulk.find()
  3. Bulk.find.upsert()
  4. Bulk.find.update()
  5. Bulk.find.updateOne()
  6. Bulk.find.replaceOne()
  7. Bulk.find.remove()
  8. Bulk.find.removeOne()

Most helpful comment

It will work great with bulk addition, this way, you just need to create on array and pass it to it.

$temp = [
            [
                'item'=> "envelopes"
            ],`enter code here`
            [
                'item'=> "envelopesas"
            ],
            [
                'item'=> "lala"
            ]
        ];

        $userData = DB::table('log')->raw( function ( $collection ) use ($temp) {

            return $collection->insertMany($temp);
        });

All 2 comments

public function update(array $values, array $options = array()) will set $options['multiple'] = true; by default and update multiple records.

public function insert(array $values) uses batchInsert as well, to mimic Laravel insert behaviour.

public function delete($id = null) uses remove which remove multiple records as well.

It will work great with bulk addition, this way, you just need to create on array and pass it to it.

$temp = [
            [
                'item'=> "envelopes"
            ],`enter code here`
            [
                'item'=> "envelopesas"
            ],
            [
                'item'=> "lala"
            ]
        ];

        $userData = DB::table('log')->raw( function ( $collection ) use ($temp) {

            return $collection->insertMany($temp);
        });
Was this page helpful?
0 / 5 - 0 ratings