Custom Versioning Best Practice to Identify Duplicate docID

Hello,

I would like to implement my own versioning system by adding an incremental value to the end of my document ID for any new version of a file (where docIDs match from source to couchbase doc). What is a best practice to check if the docID already exists prior to trying to .add the document to Couchbase? It seems like a huge performance hit to use a .get(docid) prior to adding every single document I need to insert. Is it possible and is it best practice to catch the DocumentAlreadyExistsException and then implement the versioning logic to update the docID with an incremental value there ? Thank you for any guidance.

What is a best practice to check if the docID already exists prior to trying to .add the document to Couchbase?

There’s a Bucket.exists(String id) method that checks whether a document already exists without returning its content… but you should be prepared to handle DocumentAlreadyExistsException anyway in case another process/thread is trying to insert at the same time.

Incidentally, David Maier wrote an article about document versioning in Couchbase that might give you some ideas. One of the strategies he describes is to use an atomic counter document to assign new version numbers.