I know you can pass a key or a range to return records in CouchDB, but I want to do something like this. Find X records that are X values.
So for example, in regular SQL, lets say I wanted to return records with ids that are 5, 7, 29, 102. I would do something like this:
SELECT * FROM sometable WHERE id = 5 OR id = 7 or id = 29 or id = 102
Is it possible to do this in CouchDB, where I toss all the values I want to find in the key array, and then CouchDB searches for all of those records that could exist in the “key parameter”?
You can do a POST as documented on CouchDB wiki. You pass the list of keys in the body of the request.
The downside is that a POST request is not cached by the browser.
Alternatively, you can obtain the same response using a GET with the
keysparameter. For example, you can query the view_all_docswith:which, properly URL encoded, becomes:
this should give better cacheability, but keep in mind that
_all_docschanges at each doc update. Sometimes, you can workaround this by defining your own view with only the needed documents.