Android couchdb lite view doesn't refresh

I’m using a View to filter rows by some criteria but the retrieved rows are out of date each time. I need to delete the view before to get the last rows…

View customListView = database.getView(CUSTOM_LIST_VIEW);
customListView.setMap(new Mapper() {
    public void map(Map<String, Object> properties, Emitter emitter) {
        if (properties.containsKey(key)) {
            if (properties.get(key).equals(value)) {
                emitter.emit("values", properties);
}, "2");
Query query = customListView.createQuery();

What is “value” in this case? Your view function needs to be “pure,” which means you cannot use external variables when making your view function. You must emit your rows based only on the data contained within the properties passed into the “map” function or you will get unexpected results.

I pass the key and value of some property of the Document to filter the rows I’m getting from the View, this is working as expected. But the problem is if some data, change after creating the View, the View is not refreshed by the changes even if I set this line: query.setIndexUpdateMode(Query.IndexUpdateMode.BEFORE); to reindex the View before the Query.

As I said before, this is not a legal thing to do if “key” or “value” are variables set outside of the “map” function. You can only use values from inside the “properties” dictionary passed into the “map” function. Views are not indexed from the beginning every time. The IndexUpdateMode you mention will update the index of the view starting from the last updated change, not from the beginning.