user977828
user977828

Reputation: 7679

retrieving selected documents in couchdb

For example I have documents in couchdb which have the following Ids (1,2,3,4,...,n) and I want just to retrieve e.g. three Ids (2,4,7).

Do I have to query each of them or can I pass anyhow an array with the ids ([2,4,7]) to the view?

Upvotes: 2

Views: 424

Answers (1)

Kim Stebel
Kim Stebel

Reputation: 42037

You can get all the documents with a given list of IDs by making a POST request to the _all_docs endpoint of your database. The request body is a JSON document with a single field called keys, which contains an array of document IDs. If you want the full documents (and not just their IDs and revisions), you also have to supply include_docs=true as a query argument. Here is an example with curl:

curl https://example.com/db/_all_docs?include_docs=true -X POST -d '
{ "keys": ["2", "4", "7"] }' 

Upvotes: 4

Related Questions