Skip to content

About

The official Couchbase SDK for .NET Core and Full Frameworks

Topics

Resources

Contributing

Security policy

Stars

284 stars

Watchers

45 watching

Forks

Latest commit

 

History

2,843 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Couchbase logo

Couchbase .NET SDK

The official .NET client for Couchbase Server and Couchbase Capella.

NuGet Downloads Build License

Documentation · API Reference · Release Notes · Forums · Discord

Install

dotnet add package CouchbaseNetClient

See the compatibility page for supported .NET versions and Couchbase Server versions.

Quick start

using Couchbase;

await using var cluster = await Cluster.ConnectAsync(
    "couchbase://localhost", "Administrator", "password");

var bucket = await cluster.BucketAsync("travel-sample");
var collection = await bucket.DefaultCollectionAsync();

// Write and read a document
await collection.UpsertAsync("user::1", new User("Ada", "C#"));
var result = await collection.GetAsync("user::1");
Console.WriteLine(result.ContentAs<User>());

// Run a SQL++ query
var query = await cluster.QueryAsync<User>(
    "SELECT u.* FROM `travel-sample` u USE KEYS 'user::1'");
await foreach (var row in query.Rows)
{
    Console.WriteLine(row);
}

record User(string Name, string Language);

To connect to Capella, use the couchbases:// connection string from the Capella UI. The getting started guide shows the full setup for Capella and for a local cluster.

Transactions

A transaction changes several documents as one unit. Either all the changes commit, or none do.

await collection.UpsertAsync("account::alice", new Account("Alice", 100));
await collection.UpsertAsync("account::bob", new Account("Bob", 0));

// Move 20 from Alice to Bob
await cluster.Transactions.RunAsync(async ctx =>
{
    var aliceDoc = await ctx.GetAsync(collection, "account::alice");
    var bobDoc = await ctx.GetAsync(collection, "account::bob");

    var alice = aliceDoc.ContentAs<Account>()!;
    var bob = bobDoc.ContentAs<Account>()!;

    await ctx.ReplaceAsync(aliceDoc, alice with { Balance = alice.Balance - 20 });
    await ctx.ReplaceAsync(bobDoc, bob with { Balance = bob.Balance + 20 });
});

record Account(string Owner, decimal Balance);

Learn more

Packages

Package Description
CouchbaseNetClient The core SDK
Couchbase.Extensions.DependencyInjection Register the cluster and buckets with Microsoft.Extensions.DependencyInjection
Couchbase.Extensions.OpenTelemetry Export SDK traces and metrics with OpenTelemetry

Related projects

Project Description Links
Operational Insights .NET SDK Connect to an Operational Insights cluster and run SQL++ queries Docs · NuGet
EF Core provider Use Couchbase as an Entity Framework Core database Docs · NuGet · GitHub

Get help

Contributing

We welcome contributions. Read CONTRIBUTING.md before you open a pull request.

License

Apache 2.0. See LICENSE.

About

The official Couchbase SDK for .NET Core and Full Frameworks

Topics

Resources

Contributing

Security policy

Stars

284 stars

Watchers

45 watching

Forks

Releases

Packages

Used by

Contributors

Languages