Book Image

Couchbase Essentials

Book Image

Couchbase Essentials

Overview of this book

Table of Contents (15 chapters)
Couchbase Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Couchbase .NET SDK


The Couchbase .NET SDK is a purely C#-based library. Currently, the latest version is 2.0. This version contains support for .NET 4.5+.

Current version

This SDK should be used for all development purposes against all Couchbase Server versions from 2.5 to 3.x. Version 1.3 of the SDK was developed to support earlier versions of Couchbase Server.

How to obtain it

The .NET developers will most likely want to use NuGet to add the Couchbase .NET SDK to their Visual Studio projects. To install Couchbase SDK 2.0, run the following command in Package Manager Console:

PM> Install-Package CouchbaseNetClient

Additionally, the SDK team publishes the .NET binaries, which can be found at http://docs.couchbase.com/developer/dotnet-2.0/download-links.html. The source code for the library is available on GitHub at https://github.com/couchbase/couchbase-net-client.

The basics

The following snippet demonstrates the basics of using the Couchbase .NET SDK:

//Configure the cluster defaulting to "127.0.0.1"
var cluster = new Cluster();

//Open a bucket connection defaulting to "default"
var bucket = cluster.OpenBucket();

//Create, and store a JSON document
var document = new Document<dynamic> { 
  Id = "somekey", {
    Content = new { Message = "Hello, World!" };
bucket.Upsert(document);

//Read the document
var savedMessage = bucket.GetDocument<dynamic>("somekey");

// Close the bucket connection
bucket.Dispose();