Fork me on GitHub The .NET Couchbase SDK provides a way to store and retrieve your objects to and from a Couchbase cluster. It can be used via a synchronous or asynchronous interface.

Storing Documents

You can store items by using the Upsert<T> method. This method will suitably serialize your data structure and store it on the cluster. To store a document, just create a new Document object, and fill in the fields you need:
var doc = new Document<string>() {
  Id = "document_id",
  Content = "Hello World!"
You can store anything serializable in the Content field, not just strings.
After the document has been created, you can store it in the cluster by using the Upsert method:
Upsert is a combination of insert and update and will either replace an existing item if it exists, or create it anew if it's not yet present.

Retrieving Documents

To retrieve a document, use the bucket's GetDocument method. This contains status information and the contents of the document:
var result = bucket.GetDocument("document_id");
Console.WriteLine(result.Content); // Prints "Hello World!"