pythoncouchbase-view

No row returned when querying a couchbase view with python


I'm trying to query a view from the python sdk but I have no row returned.

My map function is :

function (doc, meta) {
  if (doc.EXENUM_A !== null)
  {
    if (doc.PRS != null) {
        emit(doc.EXENUM_A, doc.PRS);
    }
  }
}

The reduce one is :

function (keys, values) {
  for (k in keys) {
    result = {};
    for (v in values) {
      if (!(values[v] in result)) {
              result[values[v]] = 0;
      }
      result[values[v]] += 1;
    }
        return [keys[k], result];
  }
}

When I execute this query in the couchbase webui, i have the expected result.

But when I try to query it from python, i have an empty resultset :

from couchbase.bucket import Bucket
from couchbase.views.iterator import View
import os
import fnmatch

cb=Bucket('couchbase://172.17.0.2:8091/my_db', password="my_password")

view = View(cb, "dev_testview", "by_num", limit=10,reduce=True)

for row in view:
    print(row.key)

Have I missed something ?

This view is still a dev_view. Do I have to publish it in production before I can query it from python ?


Solution

  • I found the answer. It comes from parameters i had to add

    view = View(cb, "dev_testview", "by_num", limit=10, reduce=True, group=True, inclusive_end=False)