Couchbase lite getAllDocuments ignoring start and end key


I’ve been following the documentation here

Executing the following function returns all documents not just the ones that start with group-

include_docs: true,
start_key: ‘group-’,
end_key: “group-\uffff”
}).then(function (result) {
console.log("Row count = " + result.rows.length);
}).catch(function (err) {

Can anyone spot what I’m doing wrong?


The preferred names are startkey and endkey. You didn’t state what platform you’re on, but it looks like it’s not supporting the older names with underscores in them.


Thanks for the speedy response.

I am using the Couchbase-Lite-PhoneGap plugin and testing on Android and IOS. I have tried both start_key eng_key and startkey endkey. Nether reduce the data returned.


I’ve just tried again with the following url


IOS returns a status 400

“Invalid parameter in HTTP query or JSON body”


Returns all documents (no range)


I have now got this to work using

include_docs: true,
startkey: JSON.stringify(‘group-’),
endkey: JSON.stringify(‘group-\uffff’)
}).then(function (result) {
console.log("Row count = " + result.rows.length);

}).catch(function (err) {

I have no idea why I need to stringify the startkey and endkey. Could someone please explain so that I don’t fall down the same hole in the future.



It must have something to do with the implementation of whatever JS library you’re using to construct the XHR. (I.e. the getAllDocuments function.) Sounds like a bug in the library — it should probably be calling stringify itself on the parameters you give it.

In the REST API, when sending a GET _all_docs, the values of the startkey and endkey parameters must be JSON, so if the values are meant to be strings they need to have quotes around them. (Escaped, of course.)


Some string parameters need to be JSON.stringified, and some don’t. As a rule of thumb, any string parameter that represents a key, or keys (e.g. startkey, endkey, key etc) need to the JSON.stringified - others do not such as stale.

I’ve asked the question before, and asked for some clarification in the docs, but so far nothing.