Couchbase 3.0 Couchnode 2.0 Views startKey, EndKey issues


#1

Hi There:

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 options = {
startKey: startK,
endKey: endK,
inclusive_end: true,
stale: false
};

    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:

bad_request (invalid UTF-8 JSON: {{error,garbage_after_value},
""[{“email”:“dead_mask3000@hotmail.com”,“status”:false}]""})

Any help will be appreciated,

Regards,

Jorge


#2

Hey jrgcampuzano,

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);

Cheers, Brett


#3

Hi Brett19,

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);

query { ddoc: ‘users’,
name: ‘by_MyId’,
options: { key: ‘“7INGo”’, stale: ‘false’ } }

Cheers,

Jorge


#4

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


#5

Hey Brett19,

Sure, this is the gist link:

https://gist.github.com/jrgcampuzano/7a1cc603a07889f85cf2

I trying with .toString and get this error:

TypeError: First argument needs to be a ViewQuery or N1qlQuery.

Regards,

Jorge


#6

Hey Jorge,
Try performing something like: console.log(query.toString()).
Cheers, Brett


#7

Hi Brett,

I’m trying different ways and the results always is :
’[object Object]’

var qry = query.toString();
console.log(“qry”, qry);
// '[object Object]'
2.
var util = require(‘util’);
console.log(util.inspect(qry, {showHidden: false, depth: null}));
// '[object Object]'
3.
console.log("%j", qry);
// '[object Object]'
4.
console.dir(qry);
// ‘[object Object]’

Regards,

Jorge


#8

Hi Brett:

My Bad, the real view name is /user/ and in my code I’m using users in plural.
Now works well, thanks for your time and support.

Cheers,
Jorge


#9

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


#10

Hi 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:

http://docs.couchbase.com/developer/node-2.0/introduction.html
http://docs.couchbase.com/sdk-api/couchbase-node-client-2.0.0/ViewQuery.html

Best,

Jorge


#11

Hey Jorge,

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!

Cheers, Brett


#12

Hi Brett,

I was thinking in some examples a little bit more complete as you can see in Atomic Operations samples as well :

http://docs.couchbase.com/developer/node-2.0/atomic-operations.html

Regards,

Jorge