Where is KeyExists in 2.0 client

Hi Guys,

In the old 1.3.x .Net client libraries there was a KeyExists method in the CouchbaseClient class that checked if a document with a given key (and possible cas) existed.

Currently I cannot see this method in the new 2.0 .Net library.

Am I missing something or has this functionality been removed? If so, is there a plan to re-implement this method?




We don’t currently have an Exists method in 2.0, however the 1.3.X implementation is really just Observe with ReplicateTo.Zero and PersistTo.Zero. Given that information you can get the same behavior in 2.0 by calling it’s equivalent Observe with those parameters.

Although Exists may never become part of the IBucket interface, it would be possible to add it as an extension method. You would simply do what I described above in it’s implementation.



Hi Jeff,

Thanks but still having issues.

I have run a couple of tests.

  1. Insert a key then call Bucket.Observe(Key, 0, false, ReplicateTo.Zero, PersistTo.Zero)
    This returns DurabilityNotSatisfied
  2. Call the same as above with a Key that does NOT exist in the bucket and I get DurabilitySatisfied.

If I put the CAS value returned by the insert into the Observe of test 1 then I get DurabilitySatisfied but obviously I will not have access to the CAS when I’m just checking if a key exists.

The same results occur if the deletion bool is set to true.

My only current solution is to get the entire document and check the success flag, but this is not ideal

Any thoughts?



Mind you, if that is the expected responses then it is workable.

I can just map DurabilitySatisfied to “does not exist” and DurabilityNotSatisfied to “does exist”

Would just like confirmation on this.


@nick_adcock -

That sounds like a bug…if the key exists, you should get DurabiltySatisified, if not then DurabilityNotSatisfied.

Could you post an example to a Jira ticket?



Actually, I think he was confirming the logic.

@nick_adcock you will get a response indicating the item doesn’t exist if it isn’t there. As far as applications are concerned, it exists regardless of durability. That’s just additional information that you’d use if specifying Durability Requirements when changing data.

Of course, if there’s a failure and it’s not persisted or replicated, the change can be lost. That’s the reason the info is there. The client already has highlevel support for that though so just your low level check for existence can see if the observe command responds with the item existing or that it’s not known.

Let me know if you need some more help.

Hi Ingenthr, Jeff,

The problem I’m seeing is not an issue with checking for durability requirements per se but with using the method to check if a document exists as Jeff suggested.

All tests are done with no durability requirements (i.e. ReplicateTo.Zero and PersistTo.Zero)

  1. If I call observe with an existing key and no CAS then I get get ObserveResponse.DurabilityNotSatisfied
  2. If I call observe with an existing key and the CAS then I get get ObserveResponse.DurabilitySatisfied
  3. If I call observe with an non-existing key and no CAS then I get get ObserveResponse.DurabilitySatisfied

Now if these are the expected responses then I can code this in (i.e. set CAS to 0 and if the return is NotSatisfied then the document exists, else it doesn’t) I would just like to confirm this is the case.

It does seem a tad odd though as I would you would not know the difference between a document that has matched the durability requirements and one that simple doesn’t exist.

Thanks for your help,


@nick_adcock, @jmorris, @ingenthr,

I will also appreciate a KeyExists() method.
Are there any final conclusions here about best practice ?


Any confirmation on the correct way to do a KeyExists in Couchbase 2.0?

@radleta -

We are planning to release KeyExists in 2.1.0. Here is the ticket: Where is KeyExists in 2.0 client


@jmorris Thanks, again! Looks like 2.1.0 is the magical release for us. Looking forward to seeing it be released.


1 Like