Get the document id of all documents in couchdb da

2019-06-21 03:58发布

问题:

I have a simple question, How should I retrieve the document ids of all documents from a given database in couchdb.

I have written this code which retrieves all the documents-

     docs=CouchRest.get("http://localhost:5984/competency1/_all_docs?include_docs=true")
     puts docs.to_json

The above code displays the entire details of the database.I want to be able to list only the document id's.

I really appreciate your help.

Thanks.

回答1:

From HTTP Document API about retrieving all documents:

To get a listing of all documents in a database, use the special _all_docs URI. ... Will return a listing of all documents and their revision IDs, ordered by DocID (case sensitive)

In other words, get /competency1/_all_docs without the ?include_docs=true part. This is the best solution for several reasons.

  1. Like a map/reduce view, it supports limit, startkey,endkey` options.
  2. But unlike a map/reduce view, it does not use any additional disk space or CPU.
  3. Other people (or you in the future) will immediately recognize this query's purpose.


标签: get couchdb