I have an error: INFO: Received a View HTTP response code (400) I did not expect, not retrying.
ERROR{“error”:“bad_request”,“reason”:“attachments not supported in Couchbase”}
@cfontana0 so the first snippet works, but the rest doesn’t?
The “ConnectionManager” is not part of the SDK, can you share what it does? Also, in general in the SDK you never need to give it the full name, but rather only the name of the design doc and the name of the view.
Hi @daschl, sorry about that.
This is the code of my project:
public class Main {
private static CouchbaseCluster cluster;
private static Bucket bucket;
public static void main(String[] args) {
cluster=CouchbaseCluster.create("qa....com");
ClusterManager cManager = cluster.clusterManager("Administrator", "..");
BucketSettings b = cManager.getBucket("vdb");
bucket = cluster.openBucket("vdb", "..");
ArrayList<AsyncViewRow> returnItem = getView("design_events", "events");
}
public static ArrayList<AsyncViewRow> getView(String designDoc, String view) {
final ArrayList<AsyncViewRow> result = new ArrayList<AsyncViewRow>();
final CountDownLatch latch = new CountDownLatch(1);
System.out.println("METHOD START");
bucket.async().query(
ViewQuery.from(designDoc, view).limit(20).stale(Stale.FALSE))
.doOnNext(new Action1<AsyncViewResult>() {
@Override
public void call(AsyncViewResult viewResult) {
if (!viewResult.success()) {
System.out.println("ERROR" + viewResult.error());
} else {
System.out.println("Query is running!");
}
}
}).flatMap(new Func1<AsyncViewResult, Observable<AsyncViewRow>>() {
@Override
public Observable<AsyncViewRow> call(AsyncViewResult viewResult) {
return viewResult.rows();
}
}).subscribe(new Subscriber<AsyncViewRow>() {
@Override
public void onCompleted() {
latch.countDown();
}
@Override
public void onError(Throwable throwable) {
System.err.println("Whoops: " + throwable.getMessage());
}
@Override
public void onNext(AsyncViewRow viewRow) {
result.add(viewRow);
}
});
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return result;
}
}
....
If I use “ArrayList returnItem = getView(“design_events”, “events”);”, I get the following error: View design_events/events does not exist.
If I use “ArrayList returnItem = getView(“_design/design_events/_view”, “events”);”… I get the following error: INFO: Received a View HTTP response code (400) I did not expect, not retrying. ERROR{“error”:“bad_request”,“reason”:“attachments not supported in Couchbase”}
Oh I see. you need to use getView("events, “events”)… the design_ is not part of the design name.
Also, you can simplify your code if you want to block in .toList().toBlocking().single(), which will also give you a list of AsyncViewRows. Note that of course you can use the blocking API for that right away
I did not put the “%2F” element on the document name… but If I used it on the getView(“%2Fdesign_events”, “events”) method, I could get the list of events!
@cfontana0 glad that we worked it out. In general, you probably want to avoid things like “/” or “design_” in design document names. Maybe just name your design document “events” and the view something like “all” or whatever it does. Then it’s much easier for you to handle later on.