Is there a way to stop quering view once the IF-condition is met?
private View getSingleMessageView(final long messageId) {
View view = couchbaseWrapper.getDatabase().getView("SINGLE_MESSAGE");
if (view.getMap() == null) {
Mapper map = new Mapper() {
@Override public void map(Map<String, Object> document, Emitter emitter) {
// TODO: How to stop query once if-statement is satisfied?
if (DocType.MESSAGE.name().equals(document.get("type")) &&
document.get("user_id").equals(getCurrentUserId()) &&
String.valueOf(document.get("message_id")).equals(String.valueOf(messageId))) {
emitter.emit(document.get("message_id"), null);
}
}
};
view.setMap(map, "1.0");
}
return view;
I tried setting query.setLimit(1) but the query still goes one.