Method "exists" returns true when document is not found on bucket

We have a piece of code that checks the existence of a document before trying to retrieve it.
It first uses method “exists” from class “Collection” with a given id, if the result is true it tries to execute method “get” from the same class.
However, we are seeing instances where the “exists” method is returning a value of true even when a document does not exist in the bucket, therefore we are catching DocumentNotFoundException.
We ran our application with DEBUG level of logging for Couchbase SDK but the “exists” method does not seem generate any line of logging.

@Cesar Is there concurrent activity on the cluster when you have this problem? I am thinking something could delete the doc between the successful existence check and the unsuccessful retrieval attempt.

2 Likes

I wonder if it would be simpler (and faster) to just get the document and handle the DocumentNotFoundException when the document doesn’t exist? Can you provide more details about why it’s necessary to call exists first?

Thanks,
David

Kevin, no. There is no concurrent activity. However, we found out that the document id belonged to a document that used to be there but was deleted the day before this error started happening.

We were making use of the exists method before trying to retrieve the document exactly to avoid having to deal with the exception. Our logic was “let’s first see if the doc is there, if true let’s pull it; if not, do something else”