I have a few Visual Studio code snippets that I use regularly when testing out new installations of Couchbase Server.  I've just made them available on GitHub and Nuget.  Right now the snippets are fairly basic, but over time I'll work on creating some more best-practice and common task snippets.  At this point, the snippets are most useful for someone just starting out with the Couchbase .NET Client.

The first snippet (cbc) will take care of setting up a client instance using the default configuration (in code, not app|web.config)

var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri(“http://localhost:8091/pools/”));
config.Bucket = “default”;

var client = new CouchbaseClient(config);

There are also simple get (cbget) and store (cbstore) snippets that will save you a little typing.

client.Store(StoreMode.Set, key, value);
var item = client.Get<string>(key);

There is also a snippet for iterating over a view (cbview).

var view = client.GetView(“DesignDoc”, “ViewName”);
foreach (var row in view)
{
    var doc = client.Get(row.ItemId); //get original doc
}

You can install the snippets via Nuget:

Install-Package CouchbaseSnippets

Or you could clone the repo on GitHub:

http://github.com/jzablocki/CouchbaseSnippets

Author

Posted by John Zablocki, NET. SDK Developer, Couchbase

John Zablocki is a NET. SDK Developer at Couchbase. John is also the organizer of Beantown ALT.NET and a former adjunct at Fairfield University. You can also check out the book on Amazon named "Couchbase Essentials" which explains how to install and configure Couchbase Server.

Leave a reply