The delete method deletes an item in the
database with the specified key. Delete operations are synchronous
only.
| API Call | object.delete(key [, ruby-delete-options ]) | ||
| Asynchronous | no | ||
| Description | Delete a key/value | ||
| Returns | Boolean (
Boolean (true/false)
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
hash ruby-delete-options | Hash of options containing key/value pairs | ||
| Structure definition: | |||
:quiet (boolean) | :quiet | ||
| If set to true, the operation returns nil for failure. Otherwise it will raise error in synchronous mode. In asynchronous mode this option ignored. | |||
:cas (fixnum) | :cas | ||
| The CAS value for an object. This value created on the server and is guaranteed to be unique for each value of a given key. This value is used to provide simple optimistic concurrency control when multiple clients or threads try to update/delete an item simultaneously. | |||
| Exceptions | |||
ArgumentError | Exception object indicating failed attempt to pass a block in synchronous mode. | ||
Couchbase::Error::Connect | Exception object specifying failure to connect to a node. | ||
Couchbase::Error::KeyExists | Exception object indicating mismatch of given cas and cas for record. | ||
Couchbase::Error::NotFound | Exception object indicating key is missing. Occurs in verbose mode. | ||
For example, to delete an item you might use code similar to the following:
couchbase.delete("foo")The following illustrates use of delete in Ruby along with various parameters and settings:
#set and delete for key 'foo' in default mode c.set("foo", "bar") c.delete("foo") #=> true #attempt second delete in default mode c.delete("foo") #=> false #attempt to delete a key with quiet mode and then verbose c.set("foo", "bar") c.delete("foo", :quiet => false) #=> true c.delete("foo", :quiet => true) #=> nil (default behaviour) c.delete("foo", :quiet => false) #=> will raise Couchbase::Error::NotFound #attempt to delete with version check using cas value ver = c.set("foo", "bar") #=> 5992859822302167040 c.delete("foo", :cas => 123456) #=> will raise Couchbase::Error::KeyExists c.delete("foo", :cas => ver) #=> true