Get returns null for a document that I inserted


#1

I have inserted a few documents. Then I tried to get some of the inserted documents but I always end up getting null value back.

my code is as follows.

CouchbaseClient client = ....
client.add(key, document);

client.get(key); //returns null

#2

@srikar_nadipally, what client library are you using? and what version?


#3

Hi @avsej,

I am using the couchbase-client for java version 1.4.5.


#4

I think that because add() is asynchronous by default. You can call it like this to make sure that operation will complete before going to next line in your code:

client.add("hello", "world").getStatus();

#5

@avsej is spot on, you need to call .get() on the .add() method, because it is asynchronous.
So this code will work:

 CouchbaseClient client = ....
client.add(key, document).get();

client.get(key); //returns null