The official .NET client for Couchbase Server and Couchbase Capella.
Documentation · API Reference · Release Notes · Forums · Discord
dotnet add package CouchbaseNetClientSee the compatibility page for supported .NET versions and Couchbase Server versions.
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.
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);- Getting started
- Key Value operations
- SQL++ queries
- Transactions
- Managing connections
- API reference
- Release notes
| 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 |
| 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 |
- Ask questions on the Couchbase Forums or on Discord.
- Report bugs in the NCBC issue tracker.
We welcome contributions. Read CONTRIBUTING.md before you open a pull request.
Apache 2.0. See LICENSE.