php oncouch won't search with empty object

Go To StackoverFlow.com

1

using php on couch: php-on-couch

I'm trying to pass in a startkey and endkey, this works:

$client->startkey( array( $val1, $val2) ) ); 
$client->endkey( array( $val1 , $val2) ) ); 

however this does not work:

$client->startkey( array( $val1) ) ); 
$client->endkey( array( $val1 , '{}') ) ); 

I think PHP is having trouble with the empty object. Any ideas?

2012-04-04 21:10
by Matt


2

Is it possible that the string '{}' is not sent as an object, but instead as a string? You want to send (formatted for clarity)

startkey=%5B%22val1%22%5D        // decodes to: ["val1"]
endkey=%5B%22val1%22%2C%7B%7D%5D // decodes to: ["val1",{}]

But maybe PHP on Couch is requesting

startkey=%5B%22val1%22%5D              // decodes to: ["val1"]
endkey=%5B%22val1%22%2C%22%7B%7D%22%5D // decodes to: ["val1","{}"]

If that is the case (and I am guessing a bit), what about using an array (object) as the second element?

$client->startkey( array( $val1) ) ); 
$client->endkey( array( $val1 , array() ) ) ); 

Does that work?

2012-04-09 00:39
by JasonSmith
some quick tests prove that I believe this works. awesome - Matt 2012-04-09 21:03
I checked with the dev, apparently this works as well: code$endkey = array("test",new stdClass) - Matt 2012-04-12 14:16
This deserves more visibility. It is the correct answer and has ended my frustration. I am going to post my example as an answer only to supplement this because of code formatting, etc.. - Ryan Ore 2013-09-25 01:41


0

I am supplementing the @JasonSmith answer so that hopefully it will help someone else. This is the gist of what you need to clarify the above answer. The startkey and endkey will work if you pass them as array objects, even if you only need one parameter each.

$this->couchdb
->startkey(array($gallery_id))
->endkey(array($gallery_id))
->getView('galleries','by_galleryid');
2013-09-25 01:44
by Ryan Ore
Ads