I’m trying to migrate some views from couch 2.2.0 and couchnode 1.2, to couchbase 3.0 and couchnode 2.0 and I noticed that:
Before the startkey and endkeys are lowercase both and works well:
query.query({
startkey: startK,
endkey: endK,
stale: false
}, function(err, result) {
Now with the new version startKey and endKey are camel case :
var ViewQuery = couchbase.ViewQuery;
var query = ViewQuery.from('Beta', 'Users').custom(options);
With this changes my query view return a result, however the result is wrong, the query doesn’t evaluate the conditions startKey and endKey and the result cointains entire users document.
On the other hand vía web console the view query returns this error:
The startkey and endkey values are still lowercase. However, when using .custom, you are responsible for performing query encoding yourself. In your case, I highly suggest you use the fluent methods that are available rather than .custom to allow the SDK to do this for you, for instance:
var ViewQuery = couchbase.ViewQuery;
var query = ViewQuery.from('Beta', 'Users').range(startK, endK).stale(ViewQuery.Update.BEFORE);
Thanks a lot for your response, has been very helpful, however my query return an empty result, but when I execute this query via web console returns two docs.
My query code:
var query = ViewQuery.from(‘users’, ‘by_MyId’).key(uid).stale(ViewQuery.Update.BEFORE);
I Printed my query in node.js console :
console.log(“query”, query);
Hey Jorge,
Can you publish a gist showing the overall code you’re using? You’re code looks reasonable, and the generated query looks correct, you could also try to perform .toString on your query and check that against what you’re querying via the management console.
Cheers, Brett
Hey Jorge,
I apologize as well, I confused two of the SDKs that I work on and toString is not available on Node.js, we simply perform querystring.stringify on the options object! Hopefully this might help next time, but I am glad you’ve got it working!
Cheers, Brett
Ok, no problem, things happend, on the other hand and just to improve my knowledge skills on ViewQuery, do you have some link or links for couchnode versión 2.0? at the moment I have this:
The links you provided are probably your best bet for up-to-date information. If you have any suggestions for content to enhance the documentation, please let me know!