I would like to query for a list of particular documents with one call to CouchDB.
With SQL I would do something like
SELECT *
FROM database.table
WHERE database.table.id
IN (2,4,56);
What is a recipe for doing this in CouchDB by either _id or another field?
You need to use views
keysquery parameter to get records with keys in specified set.And then
To retrieve document content in same time just add
include_docs=Truequery parameter to your request.UPD: Probably, you might be interested to retrieve documents by this reference ids (2,4,56). By default CouchDB views “maps” emitted keys with documents they belongs to. To tweak this behaviour you could use linked documents trick:
And now request
will return rows with
idfield that points to document that holds2,4and56keys anddocone that contains referenced document content.