src/CouchDB/Database.php
public function insert(array &$doc)
    {
        if (isset($doc['_id'])) {
            $clone = $doc;
            unset($clone['_id']);

            $response = $this->client->request('PUT', "/{$this->name}/{$doc['_id']}", [
                'body'    => JSONEncoder::encode($clone),
                'headers' => ['Content-Type' => 'application/json'],
            ]);
        } else {
            $response = $this->client->request('POST', "/{$this->name}/", [
                'body'    => JSONEncoder::encode($doc),
                'headers' => ['Content-Type' => 'application/json'],
            ]);
        }

        if (201 !== $response->getStatusCode()) {
            throw new Exception('Unable to save document');
        }

        $value = JSONEncoder::decode((string) $response->getBody());

        $doc['_id'] = $value['id'];
        $doc['_rev'] = $value['rev'];
    }
public function insert(array &$doc)
    {
        if (isset($doc['_id'])) {
            $clone = $doc;
            unset($clone['_id']);

            $response = $this->client->request('PUT', "/{$this->name}/{$doc['_id']}", [
                'body'    => JSONEncoder::encode($clone),
                'headers' => ['Content-Type' => 'application/json'],
            ]);
        } else {
            $response = $this->client->request('POST', "/{$this->name}/", [
                'body'    => JSONEncoder::encode($doc),
                'headers' => ['Content-Type' => 'application/json'],
            ]);
        }

        if (201 !== $response->getStatusCode()) {
            throw new Exception('Unable to save document');
        }

        $value = JSONEncoder::decode((string) $response->getBody());

        $doc['_id'] = $value['id'];
        $doc['_rev'] = $value['rev'];
    }
public function insert ( array & $ doc ) { if ( isset ( $ doc [ '_id' ] ) ) { $ clone = $ doc ; unset ( $ clone [ '_id' ] ) ; $ response = $ this -> client -> request ( 'PUT' , "/{$this->name}/{$doc['_id']}" , [ 'body' => JSONEncoder :: encode ( $ clone ) , 'headers' => [ 'Content-Type' => 'application/json' ] , ] ) ; } else { $ response = $ this -> client -> request ( 'POST' , "/{$this->name}/" , [ 'body' => JSONEncoder :: encode ( $ doc ) , 'headers' => [ 'Content-Type' => 'application/json' ] , ] ) ; } if ( 201 !== $ response -> getStatusCode ( ) ) { throw new Exception ( 'Unable to save document' ) ; } $ value = JSONEncoder :: decode ( ( string ) $ response -> getBody ( ) ) ; $ doc [ '_id' ] = $ value [ 'id' ] ; $ doc [ '_rev' ] = $ value [ 'rev' ] ; }
Insert a new document.

@param array $doc

@deprecated To update a document use Database::update, it will be removed in version 2

@throws Exception
Insert a new document .