Hi I am new to couchbase/couchbase-lite and i try to query a view with multiple keys without success. Her is how the map function looks:
public void map(Map<String, Object> doc, Emitter emitter) {
if (doc.get("type").equals("my_type") {
List<Object> keys = new ArrayList<Object>();
keys.add(doc.get("key_1"));
keys.add(doc.get("key_2"));
emitter.emit(keys, null);
}
}
My problem is that i need to query the view either only with key_1 or with a combination of key_1 and key_2 like so
List<Object> keys = new ArrayList<Object>();
keys.add(key_1);
if (key_2 != null) keys.add(key_2);
query.setKeys(keys);
results = query.run()
However the results are always empty. Do i overlook anything?
Two emits doesn't work. If you give a ArrayList in setKeys() method, each key in the List match the each key in emit. If you want to match two keys, add keys ArrayList into another List. Then pass it to setKeys() method. Like this,
This is the solution, We need to add keys into another
List<Object>
https://github.com/couchbase/couchbase-lite-android/issues/740