How to set startKey and endKey?

Hi,

I’m trying to set startKey and endKey values for a view query. After searching this forum, I’ve came with the following code.

$q = CouchbaseViewQuery::from('soemthing', 'something')
        ->custom([
            'startKey' => ['something'],
            'endKey' => ['something', '{}']
        ]);

I get “Array to string conversion” exception from [CouchbaseNative]/CouchbaseViewQuery.class.php file.

My startKey and endKey in web ui are [“parent”] and [“parent”, {}], which shows up as “startkey=%5B"parent”%5D&endkey=%5B"parent"%2C+%7B%7D%5D" in my browser.

How do I set [“parent”] and [“parent”,{}] as startKey and endKey in PHP SDK?

Okay…

it’s not ‘startKey’…it’s ‘startkey’ and I had to construct the string myself.

$startKey = “[”{$id}"]";

is there a better way?

Try this:

$q = CouchbaseViewQuery::from('soemthing', 'something')
        ->custom(array('startkey' => 'something',
                       'endkey' => ['something', "\u0FFF"])
        );

Hi Dave,

Unfortunately, I get “Array to string conversion” exception from [CouchbaseNative]/CouchbaseViewQuery.class.php file.

whenever I set an array for startKey or endKey…

Okay…found it.

I need to use range($start, $end) to set startkey and endkey. The method accept Array.

For the {}, I need to pass new stdClass.

$q = CouchbaseViewQuery::from(‘soemthing’, ‘something’)
->range([‘soemthing’], [‘something’, new stdClass]);