public function batchInsert($rows, $validate = true)
    {
        if ($validate) {
            $document = $this->createDocument();
            foreach ($rows as $row) {
                $document->merge($row);

                if (!$document->isValid()) {
                    throw new InvalidDocumentException('Document is invalid on batch insert');
                }

                $document->reset();
            }
        }

        $result = $this->getMongoCollection()->batchInsert($rows);

        // If the w parameter is set to acknowledge the write,
        // returns an associative array with the status of the inserts ("ok")
        // and any error that may have occurred ("err").
        if (is_array($result)) {
            if ($result['ok'] != 1) {
                throw new Exception('Batch insert error: ' . $result['err']);
            }

            return $this;
        }

        // Otherwise, returns TRUE if the batch insert was successfully sent,
        // FALSE otherwise.
        if (!$result) {
            throw new Exception('Batch insert error');
        }

        return $this;
    }
public function batchInsert($rows, $validate = true)
    {
        if ($validate) {
            $document = $this->createDocument();
            foreach ($rows as $row) {
                $document->merge($row);

                if (!$document->isValid()) {
                    throw new InvalidDocumentException('Document is invalid on batch insert');
                }

                $document->reset();
            }
        }

        $result = $this->getMongoCollection()->batchInsert($rows);

        // If the w parameter is set to acknowledge the write,
        // returns an associative array with the status of the inserts ("ok")
        // and any error that may have occurred ("err").
        if (is_array($result)) {
            if ($result['ok'] != 1) {
                throw new Exception('Batch insert error: ' . $result['err']);
            }

            return $this;
        }

        // Otherwise, returns TRUE if the batch insert was successfully sent,
        // FALSE otherwise.
        if (!$result) {
            throw new Exception('Batch insert error');
        }

        return $this;
    }
public function batchInsert ( $ rows , $ validate = true ) { if ( $ validate ) { $ document = $ this -> createDocument ( ) ; foreach ( $ rows as $ row ) { $ document -> merge ( $ row ) ; if ( ! $ document -> isValid ( ) ) { throw new InvalidDocumentException ( 'Document is invalid on batch insert' ) ; } $ document -> reset ( ) ; } } $ result = $ this -> getMongoCollection ( ) -> batchInsert ( $ rows ) ; // If the w parameter is set to acknowledge the write, // returns an associative array with the status of the inserts ("ok") // and any error that may have occurred ("err"). if ( is_array ( $ result ) ) { if ( $ result [ 'ok' ] != 1 ) { throw new Exception ( 'Batch insert error: ' . $ result [ 'err' ] ) ; } return $ this ; } // Otherwise, returns TRUE if the batch insert was successfully sent, // FALSE otherwise. if ( ! $ result ) { throw new Exception ( 'Batch insert error' ) ; } return $ this ; }
Insert multiple documents defined as arrays

Prior to version 1.5.0 of the driver it was possible to use MongoCollection::batchInsert(),
however, as of 1.5.0 that method is now discouraged.

You can use Collection::createBatchInsert()

@param array $rows list of documents to insert, defined as arrays
@return \Sokil\Mongo\Collection
@throws \Sokil\Mongo\Document\InvalidDocumentException
@throws \Sokil\Mongo\Exception
Insert multiple documents defined as arrays