Couchbase \ Exception \ DecodingFailureException on missing document from multiple documents on a getmulti operation

in PHP SDK when I do a get multi on some documents (JSON) if one of the documents is missing, I am getting this exception:

Couchbase\Exception\DecodingFailureException: unable to decode bytes with JsonTranscoder in ./vendor/couchbase/couchbase/Couchbase/JsonTranscoder.php on line 98

is there a way to avoid this, and for the missing document to just return null?

Hi @flaviu, the GetMulti operation runs a get on each of the specified IDs and returns an array of GetResults, if an error occurs during one of the gets (such as if one of the documents is missing), then that GetResult’s error field will be populated, so, if you wanted to e.g. print all of the successful results and ignore the errored gets, you could do something like:

$results = $collection->getMulti($ids);
foreach($results as $res) {
    if (!$res->error()) {

Hope that helps!

This topic was automatically closed after 90 days. New replies are no longer allowed.