Search code examples
javacouchdbektorp

Query View doesn't return any values in couchdb


I have a view defined as:

function(doc) 
{ 
    if (doc.type="user")
    {
        emit([doc.uid, doc.groupid], null);
    } 
}

In Java code, I have written

List<String> keys = new ArrayList<String>();
keys.add("93");
keys.add("23");
ViewQuery q = createQuery("getProfileInfo").descending(true).keys(keys).includeDocs(true);
ViewResult vr = db.queryView(q);
List<Row> rows = vr.getRows();
for (Row row : rows) {
  System.out.println("Key--->"+row.getKey());
  System.out.println("Value--->"+key);
}

My code always returns 0 rows - what have I missed?


Solution

  • Modified the code to

    ComplexKey keys = ComplexKey.of(“93”,”23”);
    ViewQuery q = createQuery("getProfileInfo").descending(true).key(keys).includeDocs(true); 
    ViewResult vr = db.queryView(q); 
    List<Row> rows = vr.getRows(); 
    for (Row row : rows) { 
      System.out.println("Key--->"+row.getKey()); 
      System.out.println("Value--->"+row.getValue()); 
    }
    

    and it works fine now.