Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the document id of all documents in couchdb database

Tags:

get

couchdb

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.

like image 387
karthi Avatar asked Sep 27 '11 11:09

karthi


People also ask

Which of the following built-in view returns a listing of all documents in the Apache CouchDB database?

2. /{db}/_all_docs. Executes the built-in _all_docs view, returning all of the documents in the database. With the exception of the URL parameters (described below), this endpoint works identically to any other view.

How do I get CouchDB data?

CouchDB will be downloaded to your system in the form of setup file named setup-couchdb-1.6. 1_R16B02.exe. Run the setup file and proceed with the installation. After installation, open built-in web interface of CouchDB by visiting the following link: http://127.0.0.1:5984/.

Is CouchDB a document database?

Apache CouchDB (CouchDB (link resides outside IBM)) is an open source NoSQL document database that collects and stores data in JSON-based document formats.

What is a document in CouchDB?

Advertisements. Documents are CouchDB's central data structure. Contents of the database will be stored in the form of Documents instead of tables. You can create these documents using cURL utility provided by CouchDB, as well as Futon.


1 Answers

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.
like image 51
yojimbo87 Avatar answered Sep 19 '22 13:09

yojimbo87