CouchbaseViewQuery setting startkey and end key

Using PHP SDK 2.0.4 I am unable to set startkey or endkey.
I tried $query->range(start,end,inclusive_end);
I also tried $query->custom() as per the doc.

I am trying to set both these keys as an array. It works great in the earlier SDK but not in 2.0.
The options variable does work but I have not seen any examples for startkey and endkey.
Couchbase server is 3.0. As I stated using a previous version of the SDK pre 2.0 everything worked great.

---------Here is the view
function (doc,meta) {
emit([doc.messageType,parseInt(doc.lastUpdate)], null);
}
----------Here is a sample of the PHP code:

$myCluster = new CouchbaseCluster($node);
$myBucket = $myCluster->openBucket($bucket);
$query = CouchbaseViewQuery::from(‘messages’, ‘by_list’);
Tried
$startArray = array(‘messageTypeA’,0);
$endArray = array(‘messageTypeA’,1424196239609);

$query->custom(array(‘startkey’=>$startArray,‘endkey’=>$endArray));
Tried
$query->range($startArray,$endArray,true);

$query->options = array(‘skip’=>0,‘limit’=>10,‘descending’=>false);
$results = $myBucket->query($query);

The data comes back sorted as it should but the doc.messageType is ignored.

Thank you.

Keith

Hey layerxfounder,

The options object that exists on the CouchbaseViewQuery is actually intended to be private, it is a bug that it is exposed directly. The options array is used by all the internal functions to build up your query. In your case, you are building the range using ->range, and then by specifying the options array directly you are eradicating the values set by the range function. You should use ->skip, ->limit and ->order in place of specifying the options array directly.

Cheers, Brett

Hey Brett,

I did as you said and works as advertised. :smile:
Guess I shouldn’t have read the source so close. It was a little confusion since there are limited examples.

Thank You Much,

I reposted my solution so this may help someone else. :v:

define (‘ORDER_ASCENDING’,1);
define (‘ORDER_DESCENDING’,2);
$myCluster = new CouchbaseCluster($node);
$myBucket = $myCluster->openBucket($bucket);
$query = CouchbaseViewQuery::from($designDoc, $designView);
$startArray = array(‘messageTypeA’,0);
$endArray = array(‘messageTypeA’,1424196239609);
$query->range($startArray,$endArray,true);
$query->skip(0);
$query->limit(10);
$query->order(ORDER_DESCENDING);

    $results = $myBucket->query($query);

Keith

Brett,

In regards to this thread. I have tried to implement the key and keys methods for the CouchbaseViewQuery. Should I user Custom or key or keys. The API does not expose methods other than custom,skip,limit,stale.

How about all the view options?

So for the confusion.

Thanks

Hey layerxfounder,

You should be using ->key(KEY) and ->keys(ARRAY_OF_KEYS) to perform view queries that specify key/keys options.

Cheers, Brett