public function batchInsert(array &$a, array $options = [])
    {
        if (empty($a)) {
            throw new \MongoException('No write ops were included in the batch');
        }

        $continueOnError = isset($options['continueOnError']) && $options['continueOnError'];

        foreach ($a as $key => $item) {
            try {
                if (! $this->ensureDocumentHasMongoId($a[$key])) {
                    if ($continueOnError) {
                        unset($a[$key]);
                    } else {
                        trigger_error(sprintf('%s expects parameter %d to be an array or object, %s given', __METHOD__, 1, gettype($a)), E_USER_WARNING);
                        return;
                    }
                }
            } catch (MongoException $e) {
                if (! $continueOnError) {
                    throw $e;
                }
            }
        }

        try {
            $result = $this->collection->insertMany(
                TypeConverter::fromLegacy(array_values($a)),
                $this->convertWriteConcernOptions($options)
            );
        } catch (\MongoDB\Driver\Exception\Exception $e) {
            throw ExceptionConverter::toLegacy($e, 'MongoResultException');
        }

        if (! $result->isAcknowledged()) {
            return true;
        }

        return [
            'ok' => 1.0,
            'connectionId' => 0,
            'n' => 0,
            'syncMillis' => 0,
            'writtenTo' => null,
            'err' => null,
        ];
    }
public function batchInsert(array &$a, array $options = [])
    {
        if (empty($a)) {
            throw new \MongoException('No write ops were included in the batch');
        }

        $continueOnError = isset($options['continueOnError']) && $options['continueOnError'];

        foreach ($a as $key => $item) {
            try {
                if (! $this->ensureDocumentHasMongoId($a[$key])) {
                    if ($continueOnError) {
                        unset($a[$key]);
                    } else {
                        trigger_error(sprintf('%s expects parameter %d to be an array or object, %s given', __METHOD__, 1, gettype($a)), E_USER_WARNING);
                        return;
                    }
                }
            } catch (MongoException $e) {
                if (! $continueOnError) {
                    throw $e;
                }
            }
        }

        try {
            $result = $this->collection->insertMany(
                TypeConverter::fromLegacy(array_values($a)),
                $this->convertWriteConcernOptions($options)
            );
        } catch (\MongoDB\Driver\Exception\Exception $e) {
            throw ExceptionConverter::toLegacy($e, 'MongoResultException');
        }

        if (! $result->isAcknowledged()) {
            return true;
        }

        return [
            'ok' => 1.0,
            'connectionId' => 0,
            'n' => 0,
            'syncMillis' => 0,
            'writtenTo' => null,
            'err' => null,
        ];
    }
public function batchInsert ( array & $ a , array $ options = [ ] ) { if ( empty ( $ a ) ) { throw new \ MongoException ( 'No write ops were included in the batch' ) ; } $ continueOnError = isset ( $ options [ 'continueOnError' ] ) && $ options [ 'continueOnError' ] ; foreach ( $ a as $ key => $ item ) { try { if ( ! $ this -> ensureDocumentHasMongoId ( $ a [ $ key ] ) ) { if ( $ continueOnError ) { unset ( $ a [ $ key ] ) ; } else { trigger_error ( sprintf ( '%s expects parameter %d to be an array or object, %s given' , __METHOD__ , 1 , gettype ( $ a ) ) , E_USER_WARNING ) ; return ; } } } catch ( MongoException $ e ) { if ( ! $ continueOnError ) { throw $ e ; } } } try { $ result = $ this -> collection -> insertMany ( TypeConverter :: fromLegacy ( array_values ( $ a ) ) , $ this -> convertWriteConcernOptions ( $ options ) ) ; } catch ( \ MongoDB \ Driver \ Exception \ Exception $ e ) { throw ExceptionConverter :: toLegacy ( $ e , 'MongoResultException' ) ; } if ( ! $ result -> isAcknowledged ( ) ) { return true ; } return [ 'ok' => 1.0 , 'connectionId' => 0 , 'n' => 0 , 'syncMillis' => 0 , 'writtenTo' => null , 'err' => null , ] ; }
Inserts multiple documents into this collection

@link http://www.php.net/manual/en/mongocollection.batchinsert.php
@param array $a An array of arrays.
@param array $options Options for the inserts.
@throws MongoCursorException
@return mixed If "safe" is set, returns an associative array with the status of the inserts ("ok") and any error that may have occured ("err"). Otherwise, returns TRUE if the batch insert was successfully sent, FALSE otherwise.
Inserts multiple documents into this collection