Couchbase lite getAllDocuments ignoring start and end key

I’ve been following the documentation here http://developer.couchbase.com/documentation/mobile/1.2/develop/references/couchbase-lite/rest-api/database/get-all-docs/index.html

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

database.getAllDocuments({
include_docs: true,
start_key: ‘group-’,
end_key: “group-\uffff”
}).then(function (result) {
console.log("Row count = " + result.rows.length);
}).catch(function (err) {
console.error(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

http://lite.couchbase./mydb/_all_docs?endkey=group-%EF%BF%BF&include_docs=true&startkey=group-

IOS returns a status 400

“Invalid parameter in HTTP query or JSON body”

Android

Returns all documents (no range)

I have now got this to work using

database.getAllDocuments({
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) {
console.log(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.

Thanks

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.