1

I don't get why this doesn't delete all the documents in the view. I'm using Couchbase Java SDK 2.1.3 with Couchbase 3.0.3.

public class Main {
    public static void main(String[] args) {
        // Create a cluster reference
        CouchbaseCluster cluster = CouchbaseCluster.create("http://192.168.236.141");
        Bucket bucket = cluster.openBucket("default");
        ViewResult result = bucket.query(ViewQuery.from("maintenance", "all_doc"));
        System.out.println("Will remove " + result.totalRows() + " documents");
        for (ViewRow row : result) {
            System.out.println(row.document().content().getString("id"));
            bucket.remove(row.id());
        }
        cluster.disconnect();
    }
}

No matter how many times I run it, the output of this program is always "Will remove 94 documents"

The view has only a map function that looks like this:

function (doc, meta) {
  if(doc.type == "kale:doc")
  emit(meta.id, doc);
}

Can't get what I'm doing wrong!

sscarduzio
  • 5,938
  • 5
  • 42
  • 54
  • this should indeed work as expected... did you debug, see what you get from `row.id()`? were you able to confirm it maps to a document that is still there? also, can you try adding `.stale(false)` after the `ViewQuery.from(...)` see if by any chance the engine didn't return you 94 stale results? – Simon Baslé Jun 15 '15 at 20:47
  • I added .stale(Stale.FALSE)) after the from, no change :( – sscarduzio Jun 16 '15 at 07:54
  • 1
    on a side note, in your view if you emit the whole doc it unnecessarily grows the index, prefer emitting `null`. When you access the doc on the `ViewRow` it will be fetched lazily. In the next version of the SDK (`2.2.0`) there will be an `includeDocs()` parameter on the query to do this eargerly. – Simon Baslé Jun 16 '15 at 08:10
  • Update on this: apparently my dockerized CB 3.0.3 is the culprit. I don't know why, when I target that DB I don't even get inside the for loop. When I target the CB installed in my server (3.0.1) it works as expected. Puzzled. – sscarduzio Jun 16 '15 at 09:26

0 Answers0