I’ve read on docs that it’s better to have fewer views that can be queried in interesting ways, so I set up to reduce the number of views in my app.
There was a view that emitted a single value from documents with a specific type, which I decided I would eliminate because there was already a different view that emitted that same value (along with others).
So my approach was the following:
I wanted to show a group of documents to the user. The documents have a groupId propery which the old view used to emit. It emmited it as a key, with a null value.
Now I wanted to use a different view, one that I use for general search of documents and which emits multiple properties of a document, to get the groupId of the documents. The problem with this was that if I just queried the view for the specific groupId, there was the possibility to get a document that didn’t have that groupId, but did have the same groupId value in a different property that was emited by the view. This led me to set a static value on the emit of the groupId so that I could check for that value on the query. It looks like this:
namesView = database.getView("general");
if (namesView.getMap() == null) {
namesView.setMap(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
if (document.get(TYPE) != null && document.get(TYPE).equals(REGISTRATION)) {
emitter.emit(document.get(NOMBRE), null);
emitter.emit(document.get(DORSAL), null);
emitter.emit(String.valueOf(document.get(GROUP_ID)), true);
}
}
},"34");
}
However, when I do this, the query listener doesn’t get notified when there is a change to a document.
It does get notified though when there is a new document emited by the view (as in, when I create a document that has that same groupId)
Is there something that I’m missing here? Does this work as intended?
EDIT: I’m using couchbase Lite 1.4 for android