Getting compilation error with the example given in couchbase blogs


I am newbee in Couchbase and trying to code with the help of couchbase blog. I am using Couchbase Version: 4.0.0-4051 Enterprise Edition in my current project. I am using JRE 1.6.
I have below 3 jars with latest version:
I have tried below examples from links and

Statement select = select("*").from(“beer-sample”).where(x(“test”).eq(true));
// Loads 3 documents in parallel
** .just(“doc1”, “doc2”, “doc3”)**
** .flatMap(new Func1<String, Observable>() {**
** @Override**
** public Observable call(String id) {**
** return bucket.get(id);**
** }**
** }).subscribe(new Action1() {**
** @Override**
** public void call(JsonDocument document) {**
** System.out.println("Got: " + document);**
** }**
** });**

I am getting compilation error for first example at select and x. What should be the imports for both of these?

For second example I am getting compilation error at line return bucket.get(id); Error is:

Type mismatch: cannot convert from JsonDocument to Observable

I am stuck here. Plz help me to resolve both of these issue. Let me know if your need any more information.

Quick response is appreciated.

Thanks in advance.

For the N1QL query, you need static import of Select class (for select) and of Expression class (for x, i, s).

For the multi-get, it should actually be bucket.async().get(id)… All examples in the “Mastering Observables” where (unclearly) coded as if bucket variable was of type AsyncBucket. Just use bucket.async() instead.

Note that version 2.2.x should be preferred for N1QL querying, since 2.1 only has partial support tuned for the beta of N1QL. The documentation has evolved a little and can now be found at and

1 Like

Some of the documentation you point to is a bit older there, probably because search results are showing that higher. The best source for querying help is is through the developer guide and it has a more complete example that it links to. The individual SDK docs have some further detail as well and all of the details are in the API reference.

Hope that helps!

Many Thanks Simon for prompt reply.

I have used below imports:

But still I am getting error:

Can you plz let me know what I am missing here.

Thanks in advance.

I have already tried using async() but my requirement is to do bulk and sync read. So do we have any other alternative to do bulk sync read with observables?

According to the documentations if we use toBlocking() and single() it’ll give the same effect as we get from sync read. Can you plz confirm me if my understanding is correct.

I have used below code to do bulk sync read:

List<JsonDocument> guidDocList = Observable
                                    .flatMap(new Func1<String, Observable<JsonDocument>>() {
                                        public Observable<JsonDocument> call(String id) {
                                            return dsBucket.async().get(id );

Plz confirm me If i am doing correct.

Thanks in advance,

Thanks Matt,

Dev guide example resolved my issue.

Thanks again…

You are doing the “bulk async then block” thing right as far as I can see.

For imports, you need static import, and you used an ibm import for x which is wrong.
import static*
import static*