Getting compilation error with the example given in couchbase blogs

Hi,

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:
core-io-1.2.3
java-client-2.2.3
rxjava-1.1.0
I have tried below examples from links http://docs.couchbase.com/developer/java-2.1/querying-n1ql.html and http://docs.couchbase.com/developer/java-2.0/observables.html

Statement select = select("*").from(“beer-sample”).where(x(“test”).eq(true));
and
// Loads 3 documents in parallel
Observable
** .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 http://developer.couchbase.com/documentation/server/4.1/sdks/java-2.2/querying-n1ql.html and http://developer.couchbase.com/documentation/server/4.1/sdks/java-2.2/observables.html

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:
import com.couchbase.client.java.query.Select;
import com.couchbase.client.java.query.Statement;
import com.ibm.keymanager.logic.x;

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
                                    .from(ids)
                                    .flatMap(new Func1<String, Observable<JsonDocument>>() {
                                        @Override
                                        public Observable<JsonDocument> call(String id) {
                                            return dsBucket.async().get(id );
                                        }
                                    })
                                   .toList()
                                   .toBlocking()
                                   .single();

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 com.couchbase.client.java.query.Select.*
import static com.couchbase.client.java.query.dsl.Expression.*