get list of all view names in couchdb

4.7k Views Asked by At

Is it possible to get a list of all the views of a database in couchdb using [dscape/nano][1]? The closest I can get with just curl request is this:

http://URL/DBNAME/_all_docs?key=_design/views&include_docs=true.

The above returns all the views including the javascript functions. But I would like to extract only the view names.

2

There are 2 best solutions below

1
On BEST ANSWER

Unfortunately the only possible way of doing this is by extracting view names from the result of the query you've included in your question. Futon is doing it this way when populating drop-down list of views, so I think it is safe to assume this is the only solution.

You may also want to change your query to the following to include all design documents, instead of just the one named views:

GET /dbname/_all_docs?startkey="_design/"&endkey="_design0"&include_docs=true
0
On

In newer CouchDB versions, you can use "_design_docs" to only list the views:

GET /dbname/_design_docs

This will get you the wanted list much faster than if you'd have to go through all the docs (_all_docs).

See 1.3.3. /{db}/_design_docs of the official documentation.

Note: The documentation as of today states this is new in CouchDB version 2.2, but I successfully tested it on 2.1.