apache / nano

Nano is now part of Apache CouchDB. Repo moved to https://GitHub.com/apache/couchdb-nano

Home Page:https://github.com/apache/couchdb-nano

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Query string encoded when using array of keys

ocampeau opened this issue · comments

I am trying to use the following function

db.view(designname, viewname, [params], [callback])

My key is an array of key.
Exemple, in my view I have: key = [Montreal, Quebec, Canada], value = 1;

When I try this, I get no result:

db.view(dDoc, myView, {key:["Montreal", "Quebec", "Canada"], reduce: false}, my_callback)

After digging deep, I found that the module qs (https://www.npmjs.com/package/qs), which is a dependency of nano, format the query string like this:

reduce=false&key=%5B%22Montreal%22%2C%22Quebec%22%2C%22Canada%22%5D

The issue however is not with qs module, because this format is simply in url-encoded form and is valid for a lot of web servers. I believe the issue is with nano, since CouchDB seems to accept this kind of query string format for array key

reduce=false&key[]=Montreal&key[]=Quebec&key[]=Canada

If you want to reproduce this issue, simply use the db.view function with a key that is an array of keys, on a database that you know for sure this key returns some data.

If I'm totally wrong and just using nano the wrong way, please help me fetching data with an array of keys. Otherwise, I would be willing to help you fix this.

Thanks