Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: .NET (C#) 1.2
Community Wiki and Resources
Wiki: .NET Client Library
Download Client Library
.NET Client Library
Couchbase Developer Guide 2.0
Couchbase Server Manual 2.0
SDK Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
7 Update Operations
Chapter Sections
Chapters

7.3. Remove Methods

The Remove() method deletes an item in the database with the specified key.

API Callobject.Remove(key)
Asynchronousno
Description Delete a key/value
ReturnsObject; supported values:
 COUCHBASE_ETMPFAILTemporary failure; try the operation again 
 COUCHBASE_KEY_ENOENTRequested document ID does not exist 
 COUCHBASE_NOT_MY_VBUCKETThe command was sent to the wrong server; may be triggered during a rebalance or failover operation. Retry the operation 
 COUCHBASE_NOT_STOREDThe object was not stored 
 docidDocument ID of deleted document 
Arguments 
string key Document ID used to identify the value

Remove the item with a specified key

client.Remove("badkey");
API Callobject.ExecuteRemove(key)
Asynchronousno
Description Delete a key/value
ReturnsIRemoveOperationResult ( Remove operation result )
Arguments 
string key Document ID used to identify the value

ExecuteRemove removes an item by key and returns an instance of an IRemoveOperationResult

var result = client.ExecuteRemove("badkey");

if (! result.Succes) 
{
    Console.WriteLine("Remove failed with message {0} and status code {1}", result.Message, result.StatusCode);
    
    if (result.Exception != null)
    {
        throw result.Exception;
    }
}
API Callobject.ExecuteRemove-cas(key, casunique)
Asynchronousno
Description Delete a key/value
ReturnsIRemoveOperationResult ( Remove operation result )
Arguments 
string key Document ID used to identify the value
ulong casunique Unique value used to verify a key/value combination

ExecuteRemove removes an item by key using a CAS operation and returns an instance of an IRemoveOperationResult

var result = client.ExecuteRemove("badkey", 86753091234);

if (! result.Succes) 
{
    Console.WriteLine("Remove failed with message {0} and status code {1}", result.Message, result.StatusCode);
    
    if (result.Exception != null)
    {
        throw result.Exception;
    }
}
API Callobject.ExecuteRemove(key)
Asynchronousno
Description Delete a key/value
ReturnsIRemoveOperationResult ( Remove operation result )
Arguments 
string key Document ID used to identify the value

The ExecuteRemove() method may define persistence requirements. This operation will return success only when the key has been removed from the specified number of nodes.

PersistTo.One will ensure removal from the key's master node and not consider removal of its replicas. A common use of this option is to combine it with a non-stale view query, to guarantee that a deleted key is not returned in a view result.

var result = client.ExecuteRemove("city_NC_Raleigh", PersistTo.One);

if (! result.Succes) 
{
    Console.WriteLine("Remove failed with message {0} and status code {1}", result.Message, result.StatusCode);
    
    if (result.Exception != null)
    {
        throw result.Exception;
    }
} 
else 
{
    var view = client.GetView("cities", "by_name").Stale(StaleMode.False); 
    //safe to iterate this view, because the key has been removed from disk
    //and the index was updated.
}