Query returns a value for 'total_rows', but with an empty rows array

Hi,

I’m executing the following query in my PHP code.

    $query = CouchbaseViewQuery::from("dev_".$this->bucketName, 'followers')->key($personId);

    $result = $this->bucket->query($query);

Outputs

array (size=2)
  'total_rows' => int 2
  'rows' => 
    array (size=0)
      empty

My View Map function

function (doc, meta) {
  if (doc.action && doc.action === 'follow') {
      emit(doc.acted_on_document_id, doc.actor_document_id); 
  }
}

From the web admin interface, everything works fine. The problem is that PHP shows an empty array for the ‘rows’ key.

Is this a bug?

Hey moono326,

Without your dataset, I can’t be sure, however I suspect that your ->key($personId) does not actually match any rows. Note that the total_rows field describes the total number of rows in your index, and not the total number of rows returned for the specific query.

Cheers, Brett

Hi @brett19

Thank you for the answer. Ah…I thought ‘total_rows’ indicates # of rows matched. You’re right. I double checked $personId and I was passing an incorrect value.

Problem fixed!

Thank you!