I would like to run a CouchDB view against a specific set of keys (more than just 1 single key and not a range of startkey/endkey). The Apache Couchdb docs show its possible using GET and POST using the 'keys' query parameter:
http://wiki.apache.org/couchdb/HTTP_view_API#Querying_OptionsBut this doesnt seem to be supported by Couchrest, because when I do a POST to a view I see this error:
RestClient::MethodNotAllowed: 405 Method Not Allowed
Im not sure if this is from the couchserver (passed back to couchrest's client) or couchrest itself.
When I do a GET with the keys parameter, I end up with no documents (Im pretty sure Im URL encoding correctly). See below for code (from the rails console) that shows this:
db = CouchDb.connect('
http://localhost:5984/db')
I do this to POST to my views:
info = CouchRest.post "
http://localhost:5984/db/_design/content/views/viewname", nil, {:keys => ['a','b']}
=>RestClient::MethodNotAllowed: 405 Method Not Allowed
Example using GET via the CouchRest .view function:
db.view('viewname?keys=%5B%5B%22KEY1%22%5D%5D') # URL decoded as: '[["KEY1"]]' <= NOTE the extra set of [] needed to make this work
=> will return data
but when I try to retrieve more than 1 key or 1 key without using [[key]] syntax, it fails...
db.view('viewname?keys=%5B%22KEY1%22%5D') # URL decoded as: '["KEY1"]' <= does not work
db.view('viewname?keys=%5B%5B%22KEY1%22,%22KEY2%22%5D%5D') # URL decoded as:
'[["KEY1","KEY2"]]' <= did not URL encode the comma
db.view('viewname?keys=%5B%5B%22KEY1%22%2C%22KEY2%22%5D%5D') # URL decoded as:
'[["KEY1","KEY2"]]' <= did url encode the comma
Does someone know the correct/canonical way to do a POST to run a view
on CouchDB using the couchrest API? And could share an example or two?
Mike