How to ensure data is saved in Couchbase?
Are you in a situation where you expect data not to persist periodically due to an unstable application or Couchbase cluster, or are you just being extra careful?
In either case, what you're probably looking for are Durability options. For example:
collection.upsert("my-document", JsonObject.create().put("doc", true),
upsertOptions().durability(DurabilityLevel.MAJORITY));
DurabilityLevel
has multiple options: Majority, MajorityAndPersistToActive, PersistToMajority
, and None
.
For more details on which ones you should choose and why, check out the docs on durable writes.
Also note that if you're on an older version of Couchbase (pre-6.5 I think), there are still some durability options, but they are all "client checked" options, which means there are some edge cases (which may be very infrequently encountered).