New Visual Studio Code Snippets for the .NET Couchbase Client Library

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

Share this article
Get Couchbase blog updates in your inbox
This field is required.

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 comment

Ready to get Started with Couchbase Capella?

Start building

Check out our developer portal to explore NoSQL, browse resources, and get started with tutorials.

Use Capella free

Get hands-on with Couchbase in just a few clicks. Capella DBaaS is the easiest and fastest way to get started.

Get in touch

Want to learn more about Couchbase offerings? Let us help.