javascriptcouchdbcouchdb-nano

Nano does not understand qoutation in the url


I am using nano library to query couch. I am trying to get just the _design documents so I have the following url:

nano.get(encodeURIComponent(JSON.stringify(`_all_docs?startkey="_design/"&endkey="_design0"&include_docs=true`)));

when I try the above in post man (without encodeURIComponent and stringify) it works but the qutation seems to be an issue with nano. Any idea how I can get the above url return the list of _design docs?


Solution

    1. nano.get() should be use to get a specific document by it's id. It should not be used to make custom calls. If you want to call the _all_docs endpoint, you must use the db.list() function.
    2. You shouldn't convert the string to a JSON string. It will escapes the double quotes which breaks the URL.
    3. To make your own custom call with nano, you should instead use nano.request

    In your case, you should do something like this:

    const db = nano.use(databaseName);
    db.list({include_docs:true, startkey:"_design/", endkey:"_design0"});