Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: .NET (C#) 1.1
Community Wiki and Resources
Wiki: .NET Client Library
Download Client Library
.NET Client Library
SDK Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
5 Store Operations
Chapter Sections
Chapters

5.1. Store Methods

The Store() methods adds a value to the database with the specified key, but will fail if the key already exists in the database and the StoreMode is set to Add.

API Callobject.Store(StoreMode storemode, string key, object value)
Asynchronousno
Description Store a value using the specified key, whether the key already exists or not. Will overwrite a value if the given key/value already exists.
ReturnsBoolean ( Boolean (true/false) )
Arguments 
StoreMode storemode Storage mode for a given key/value pair
string key Document ID used to identify the value
object value Value to be stored

The Store() method is used to persist new values by key. Any class decorated with the Serializable attribute may be stored.

StoreMode.Set will behave like StoreMode.Add when the key doesn't exist and StoreMode.Replace when it does.

client.Store(StoreMode.Add, "beer", new Beer() {
    Brewer = "Thomas Hooker Brewing Company",
    Name = "American Ale"
});
API Callobject.Store(storemode, key, value, validfor)
Asynchronousno
Description Store a value using the specified key, whether the key already exists or not. Will overwrite a value if the given key/value already exists.
ReturnsBoolean ( Boolean (true/false) )
Arguments 
StoreMode storemode Storage mode for a given key/value pair
string key Document ID used to identify the value
object value Value to be stored
TimeSpan validfor Expiry time (in seconds) for key
client.Store(StoreMode.Set, "beer", new Beer() {
    Brewer = "Peak Organic Brewing Company",
    Name = "IPA"
}, TimeSpan.FromSeconds(60));
API Callobject.Store(storemode, key, value, expiresat)
Asynchronousno
Description Store a value using the specified key, whether the key already exists or not. Will overwrite a value if the given key/value already exists.
ReturnsBoolean ( Boolean (true/false) )
Arguments 
StoreMode storemode Storage mode for a given key/value pair
string key Document ID used to identify the value
object value Value to be stored
DateTime expiresat Explicit expiry time for key
client.Store(StoreMode.Replace, "beer", new Beer() {
    Brewer = "Six Point Craft Ales",
    Name = "Righteous Rye"
}, DateTime.Now.Addhours(1));
API Callobject.Store(StoreMode storemode, string key, object value)
Asynchronousno
Description Store a value using the specified key, whether the key already exists or not. Will overwrite a value if the given key/value already exists.
ReturnsBoolean ( Boolean (true/false) )
Arguments 
StoreMode storemode Storage mode for a given key/value pair
string key Document ID used to identify the value
object value Value to be stored

The ExecuteStore() method is used like the Store methods, but instead of a Boolean, returns a IStoreOperationResult, which provides detailed information about the success of the operation.

var result = client.ExecuteStore(StoreMode.Add, "beer", new Beer() {
    Brewer = "The Alchemist",
    Name = "Heady Topper"
});

if (! result.Success) {
	logger.Error(result.Message, result.Exception);
}
API Callobject.ExecuteStore(storemode, key, value, validfor)
Asynchronousno
Description Store a value using the specified key, whether the key already exists or not. Will overwrite a value if the given key/value already exists.
ReturnsIStoreOperationResult ( Store operation result )
Arguments 
StoreMode storemode Storage mode for a given key/value pair
string key Document ID used to identify the value
object value Value to be stored
TimeSpan validfor Expiry time (in seconds) for key
var client.ExecuteStore(StoreMode.Set, "beer", new Beer() {
    Brewer = "Cambridge Brewing Company",
    Name = "The Audacity of Hops"
}, TimeSpan.FromSeconds(60));
API Callobject.ExecuteStore(storemode, key, value, expiresat)
Asynchronousno
Description Store a value using the specified key, whether the key already exists or not. Will overwrite a value if the given key/value already exists.
ReturnsIStoreOperationResult ( Store operation result )
Arguments 
StoreMode storemode Storage mode for a given key/value pair
string key Document ID used to identify the value
object value Value to be stored
DateTime expiresat Explicit expiry time for key
var result = client.ExecuteStore(StoreMode.Replace, "beer", new Beer() {
    Brewer = "Long Trail Brewing Company",
    Name = "Long Trail Ale"
}, DateTime.Now.Addhours(1));