storing document with key string but not finding it

Ok I am using the couchbase client in a couchbase bucket.

I have a pojo that is serializable. Everything is working fine, the document is stored but not where I thought it would.

client is initialized to localhost default bucket.

String idStr = "RuleDefinition_" + doc_RuleDefinition.getId().toString();
client.set(idStr, gson.toJson(doc_RuleDefinition, DOC_RuleDefinition.class)).get();

When I look in the Couchbase view

function (doc, meta) {
  emit(doc.eventKey, null);
}

I see my documents in json but the key is NOT "RuleDefinition_41" as I expected with the id of 41 in the RuleDefinition pojo.

I have other pojos I want to store, and they may have an id value of 41, so I would like to store "HandlerMap_41", and "HandlerJar_41" but if the key gets stripped to just 41, then won't the second two overwrite the first?

After I deleted all the simple integer key documents, they reappeared even with the above code change.

After I deleted all the same documents again, and restarted everything, then it started working as expected/hoped.

MO

1 Answer

« Back to question.

Hello,

Not sure to follow you and what has fixed your problem, but let me explain something that you may know already but just in case. (not sure that it is the source of your issue)

The documents are "eventually" indexed, since a document is indexed:
- once it is saved on disk
- once the indexer process has been executed

So you need to be sure that the document is on disk and also need to be sure that it is indexed. You can do that by:

- check the durability constraints (persistTo.One)
See http://docs.couchbase.com/couchbase-devguide-2.2/#why-observe-items

- force the index to be up to date for example with stale=false
See: http://docs.couchbase.com/couchbase-manual-2.2/#couchbase-views-writing-...

Not that it is a bad idea to do that on each operation since you will put some slow processing in your application code.

Regards
Tug
@tgrall