How to get all docs in couchdb
Couchdb get all docs
Today I will show you how to get all the docs in couchdb. First you need to know the url to create a request with the GET method.
GET /{db}/_all_docs
GET: is the HTTP method
{db}: the name of your db. Examples could be: book, movie.
_all_docs: The name of the view.
You can use postman to try it. After the execution is complete it’s will returning all of the documents in the database.
Request:
GET /my_db_books/_all_docs HTTP/1.1 Accept: application/json Host: localhost:5984
Response:
HTTP/1.1 200 OK Cache-Control: must-revalidate Content-Type: application/json ETag: "ABC" Server: CouchDB (Erlang/OTP) Transfer-Encoding: chunked { "offset": 0, "rows": [ { "id": "3e454534def45f3f34f34f3", "key": "24767etgf4v4fc3r8765434f45f4f", "value": { "rev": "1-345gf45f5f34tg4f3ed" } }, { "id": "as23xwd2dwd23f34fg34", "key": "a4c51cdfa20ff45fd3d3d3dff", "value": { "rev": "1-9fvrvf3f34ff3d9138abb3284d" } } ], "total_rows": 2 }
What’s about if you try to using POST ?
The POST to _all_docs allows to specify multiple keys to be selected from the database.
Create a request:
POST /my_db_books/_all_docs HTTP/1.1 Accept: application/json Content-Length: 70 Content-Type: application/json Host: localhost:5984 { "keys" : [ "AAAAA", "BBBBB" ] }
Response:
{ "total_rows" : 2, "rows" : [ { "value" : { "rev" : "1-a433f3f3f4tht3r4rf3" }, "id" : "AAAAA", "key" : "AAAAA" }, { "value" : { "rev" : "1-554g45f3f3f3d23d" }, "id" : "BBBBB", "key" : "BBBBB" } ], "offset" : 0 }
So you’ve learned the many basic ways to get all the docs in couchdb. See you in the next article.