protected function truncatingSave(Collection $collection, array $generatedRow)
    {
        try
        {
            $collection->updateOne(array('_id' => $generatedRow['_id']), array('$set' => $generatedRow), array('upsert' => true));
        } catch (\Exception $e) {
            // We only truncate and retry the save if the \Exception contains this text.
            if (strpos($e->getMessage(),"Btree::insert: key too large to index") !== FALSE)
            {
                $this->truncateFields($collection, $generatedRow);
                $collection->updateOne(array('_id' => $generatedRow['_id']), array('$set' => $generatedRow), array('upsert' => true));
            }
            else
            {
                throw $e;
            }
        }
    }
protected function truncatingSave(Collection $collection, array $generatedRow)
    {
        try
        {
            $collection->updateOne(array('_id' => $generatedRow['_id']), array('$set' => $generatedRow), array('upsert' => true));
        } catch (\Exception $e) {
            // We only truncate and retry the save if the \Exception contains this text.
            if (strpos($e->getMessage(),"Btree::insert: key too large to index") !== FALSE)
            {
                $this->truncateFields($collection, $generatedRow);
                $collection->updateOne(array('_id' => $generatedRow['_id']), array('$set' => $generatedRow), array('upsert' => true));
            }
            else
            {
                throw $e;
            }
        }
    }
protected function truncatingSave ( Collection $ collection , array $ generatedRow ) { try { $ collection -> updateOne ( array ( '_id' => $ generatedRow [ '_id' ] ) , array ( '$set' => $ generatedRow ) , array ( 'upsert' => true ) ) ; } catch ( \ Exception $ e ) { // We only truncate and retry the save if the \Exception contains this text. if ( strpos ( $ e -> getMessage ( ) , "Btree::insert: key too large to index" ) !== FALSE ) { $ this -> truncateFields ( $ collection , $ generatedRow ) ; $ collection -> updateOne ( array ( '_id' => $ generatedRow [ '_id' ] ) , array ( '$set' => $ generatedRow ) , array ( 'upsert' => true ) ) ; } else { throw $ e ; } } }
Save the generated rows to the given collection.

If an exception in thrown because a field is too large to index, the field is
truncated and the save is retried.

@param Collection $collection
@param array $generatedRow The rows to save.
@throws \Exception
Save the generated rows to the given collection .