getQueryById Android

Based on ToDoLite Android sample app I am trying to get query by ID working in my app.

Note that document is created with the same id as the content:
Document document = database.getDocument(userId);

If an existing key is set in the query method query.setKeys(keys); the resulting enumerator is empty. If no keys are set to the query the enumerator contains all the elements emitted.

The Android documentation for using keys in a Query is here -

public static Query getQueryById(Database database, String userId) {
        com.couchbase.lite.View view = database.getView(BY_ID_VIEW_NAME);
        if (view.getMap() == null) {
            Mapper map = new Mapper() {
                public void map(Map<String, Object> document, Emitter emitter) {
                    if (DOC_TYPE.equals(document.get("type"))) {
                        emitter.emit(document.get("user_id"), document);
            view.setMap(map, null);
        //  TODO: Adding keys here will result in an empty enumerator 
        Query query = view.createQuery();
        java.util.List<Object> keys = new ArrayList<Object>();
        return query;

Once I get through this working, the next step would be to successfully query a View by any key in a document.

I would appreciate anyones input on how to query a View by a key on Android. Thanks.

1 Answer

« Back to question.

Sounds like a bug. Can you file an issue here?