Adding where condition in Couchbase


#1

How should I add “Where” condition in Couchlite Database(Android) just like we do in “Sqlite” ?


#2

Couchbase Lite provides Map/Reduce style query. Please read View and Query section of our documents?


#3

Thanks…
If I have any further queries i will get back to you…

– Tirtharaj


#4

Can I add multiple conditions to retrive data from Couchlite?

I want to retrive data which is shown below example–
is this possible??

private Query getAllBroadcastMessageDocumentQuery1() {
com.couchbase.lite.View view = database.getView(VIEW_USER);
if (view.getMap() == null) {
Mapper mapper = new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
String type = (String) document.get(Constants.COUCHLITE_DOC_TYPE);
String user_id = (String) document.get(Constants.USER_ID);
String provider_id = (String) document.get(Constants.PROVIDER_ID);
if (DOC_TYPE_USER.equals(type) && (USER_ID).equals(user_id) && (PROVIDER_ID).equals(provider_id)) {
emitter.emit(document.get(Constants.TIMESTAMP), document);
}
}
};
view.setMap(mapper, COUCHLITE_MAP_VERSION);
}
Query query = view.createQuery();
return query;
}


#5

You could use List as a compound key.

Example:

        view.setMap(new Mapper() {
            @Override
            public void map(Map<String, Object> document, Emitter emitter) {
                if ("task".equals(document.get("type"))) {
                    List<Object> keys = new ArrayList<Object>();
                    keys.add(document.get("list_id"));
                    keys.add(document.get("created_at"));
                    emitter.emit(keys, document);
                }
            }
        }, "1");

#6

Thanks…
If I have any further queries i will get back to you…

– Tirtharaj