Is it not possible to filter data using multiple keys using a view?

Hi,

I’m using dreamfactory on bluemix. I’m using a cloudant database for all my data. I’ve set up some views with multiple keys, as an array. I’m able to pass the key param in the url and get the filtered data using the direct API provided by cloudant, like so:

https://xxxxxxxxxxxxxxxxxx-bluemix.cloudant.com/databasename/_design/design_name/_view/view_name?limit=20&reduce=false&keys=[“key1”, “key2”]

But I’m unable to do the same using the API provided by dreamfactory. But I’m able to do it using a single key instead of an array.

So my question is, is there a way to use multiple keys with the API generated by dreamfactory? If so, please do let me know how.

Thank you

Have you tried POSTing to the view with a JSON body of the keys? That’s what I’m seeing in CouchDB’s docs, but we haven’t tested it.

This page from the CouchDB wiki indicates that keys “Must be a proper URL encoded JSON array value.” That makes me think this would work:

&keys={["key1","key2"]}

Which would be URL-encoded as:

&keys=%7B%5B%22key1%22%2C%22key2%22%5D%7D

A quick Google search on how to pass JSON arrays to PHP in URL parameters yielded this Stack Overflow answer. According to that post, you should be able to accomplish this like so:

&keys[]="key1"&keys[]="key2"

Which would be URL-encoded as:

&keys%5B%5D%3D%22key1%22%26keys%5B%5D%3D%22key2%22

Thank you for the reply.

I tried both of those methods and neither of them worked for me. Besides, aren’t these docs meant for when you directly call the database, and not through dreamfactory? Is there any other way to filter documents by multiple fields?

Also I’ve been wondering for a while, for “getRecords()” API, there are two fields named “id_field” and “id_type”. Could you let me know what they are and how they can be used? Do I use them to GET records by secondary indexes?

Thank you again.