php cloudant curl抱怨db已经存在

I have a curl request to a cloudant database to add a new document. However, whenever I run it, it complains the database already exists, I then have to rename the db in the url. This however, only creates a new empty database. What is wrong with my curl request from the following?

This is the code I use :

credentials = base64_encode($login.':'.$password);
    $curl = curl_init();

    curl_setopt_array($curl, array(
      CURLOPT_URL => $url,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "PUT",
      CURLOPT_POSTFIELDS => $data,
      CURLOPT_HTTPHEADER => array(
        'Authorization: Basic '.$credentials,
        "content-type: application/json"
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
        if($this->debug === 1) {
            echo $err;
            var_dump($info);
        }
      return false;
    } else {
      return $response;
    }

And this is the code that uses it :

$journey_data = array(
            "name" => "name",
            "TEST" => "TESTIN TED"
            );

$this->cloudent_controller = modules::load('cloudent_integration/cloudent_integration');
        $url = "https://test.cloudant.com/fubar";
        $result = $this->cloudent_controller->createDocument($url, json_encode($journey_data));
        var_dump($result);
        die;

Yes I am using code igniter and the hmvc pattern, but those are not important details as I am getting back a response.

Response :

string(95) "{"error":"file_exists","reason":"The database could not be created, the file already exists."} "

To create a new document in a couchDB server you need to send a PUT or POST request to the url where you want the document to be saved, this means you need to specify the database and the name of the document in the url:

https://test.cloudant.com/fubar/doc_id

If you send a PUT or POST request directly to a database, as I think you do, you're asking couchDB to creat that database.