Get the document id of all documents in couchdb database

霸气de小男生 提交于 2019-12-10 13:20:06

问题


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.


来源:https://stackoverflow.com/questions/7568717/get-the-document-id-of-all-documents-in-couchdb-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!