Kristian
Kristian

Reputation: 21820

CouchDB view is accessible, but won't run query

I used couchdb's PHP lib to add a view:

public function addView() {
    $design_doc = new stdClass();
    $design_doc->_id = '_design/need';
    $design_doc->language = 'javascript';
    $design_doc->views = array( 'all' => array('map' => "function(doc) { if (doc.type == 'need')  emit(doc.type, doc) }" ) );
    $result = $this->client->storeDoc($design_doc);
    return $result;
}

In my shell, I viewed its doc to confirm it was created:

curl -X GET mysite.com/bids/_design/need
{
  "_id":"_design/need",
  "_rev":"1-0ed4b41b839ade9ca36fb950cac1c39b",
  "language":"javascript",
  "views":
    {
      "all":
        {
          "map":"function(doc) { if (doc.type == 'need')  emit(doc.type, doc) }"
        }
    }
}

Then when trying to actually execute the view, it throws eacces error:

curl -X GET mysite.com/bids/_design/need/_view/all
{
  "error":"error","reason":"eacces"
}

Permissions: the instance is running as root.

Am I using the wrong syntax to execute the view query?

Could it be that there is an issue with the encoding of the string that was passed via PHP?

Upvotes: 1

Views: 820

Answers (2)

Kristian
Kristian

Reputation: 21820

There was some issue with character encoding by php. Running the exact same query in curl was successful and the view was then able to run properly

Upvotes: 0

Stephen L
Stephen L

Reputation: 181

"eacces" suggests that it's a problem with the permissions or ownership on the directory your databases are stored in.

For each database, the database server will create a subdirectory called .<db_name>_design containing a file for each design document in that database. It's likely that the user your CouchDB instance is running as doesn't have permission to create that directory, or perhaps the file within it.

Check that the directory your databases are in, and everything thereunder, is owned by the user your CouchDB is running as, and that the directories and files have sensible permissions. It's /usr/local/var/lib/couchdb if you installed from source, but will probably be different if you used a package.

Upvotes: 3

Related Questions