Couchbase Java SDK cannot get and delete documents

679 views Asked by At

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!

0

There are 0 answers