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.1. Append Methods

The Append() methods allow you to add information to an existing key/value pair in the database. You can use this to add information to a string or other data after the existing data.

The Append() methods append raw serialized data on to the end of the existing data in the key. If you have previously stored a serialized object into Couchbase and then use Append, the content of the serialized object will not be extended. For example, adding an List of integers into the database, and then using Append() to add another integer will result in the key referring to a serialized version of the list, immediately followed by a serialized version of the integer. It will not contain an updated list with the new integer appended to it. De-serialization of objects that have had data appended may result in data corruption.

API Callobject.Append(key, value)
Asynchronousno
Description Append a value to an existing key
ReturnsObject ( Binary object )
Arguments 
string key Document ID used to identify the value
object value Value to be stored

The Append() method appends information to the end of an existing key/value pair.

The sample below demonstrates how to create a csv string by appending new values.

client.Store(StoreMode.Set, "beers", "Abbey Ale");
Func<string, byte[]> stringToBytes = (s) => Encoding.Default.GetBytes(s);
client.Append("beers", new ArraySegment<byte>(stringToBytes(",Three Philosophers")));
client.Append("beers", new ArraySegment<byte>(stringToBytes(",Witte")));

You can check if the Append operation succeeded by checking the return value.

var result = client.Append("beers", new ArraySegment<byte>(stringToBytes(",Hennepin")));
if (result) {
	Console.WriteLine("Append succeeded");
} else {
	Console.WriteLine("Append failed");
}
API Callobject.Append(key, casunique, value)
Asynchronousno
Description Append a value to an existing key
ReturnsObject ( Binary object )
Arguments 
string key Document ID used to identify the value
ulong casunique Unique value used to verify a key/value combination
object value Value to be stored

The Append operation may also be used with a CAS value.

var storeResult = client.ExecuteStore(StoreMode.Set, "beers", "Abbey Ale");

Func<string, byte[]> stringToBytes = (s) => Encoding.Default.GetBytes(s);
client.Append("beers", storeResult.Cas, new ArraySegment<byte>(stringToBytes(",Three Philosophers")));
API Callobject.ExecuteAppend(key, value)
Asynchronousno
Description Append a value to an existing key
ReturnsIConcatOperationResult ( Concat operation result )
Arguments 
string key Document ID used to identify the value
object value Value to be stored

The ExecuteAppend operation is used to get an instance of an IConcatOperationResult.

client.ExecuteStore(StoreMode.Set, "beers", "Abbey Ale");
Func<string, byte[]> stringToBytes = (s) => Encoding.Default.GetBytes(s);
var result = client.ExecuteAppend("beers", new ArraySegment<byte>(stringToBytes(",Three Philosophers")));

if (! result.Sucecss)
{
    Console.WriteLine("Append failed with message {0} and status code {1}", result.Message, result.StatusCode);
    
    if (result.Exception == null)
    {
        throw result.Exception;
    }
}
API Callobject.ExecuteAppend(key, casunique, value)
Asynchronousno
Description Append a value to an existing key
ReturnsIConcatOperationResult ( Concat operation result )
Arguments 
string key Document ID used to identify the value
ulong casunique Unique value used to verify a key/value combination
object value Value to be stored

The ExecuteAppend operation may also be used with a CAS value.

var storeResult = client.ExecuteStore(StoreMode.Set, "beers", "Abbey Ale");

Func<string, byte[]> stringToBytes = (s) => Encoding.Default.GetBytes(s);
var appendResult = client.ExecuteAppend("beers", storeResult.Cas, new ArraySegment<byte>(stringToBytes(",Three Philosophers")));

if (! appendResult.Sucecss)
{
    Console.WriteLine("Append failed with message {0} and status code {1}", appendResult.Message, appendResult.StatusCode);
    
    if (appendResult.Exception == null)
    {
        throw appendResult.Exception;
    }
}