Couchbase.AnalyticsClient 1.0.1

Prefix Reserved
dotnet add package Couchbase.AnalyticsClient --version 1.0.1
                    
NuGet\Install-Package Couchbase.AnalyticsClient -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Couchbase.AnalyticsClient" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Couchbase.AnalyticsClient" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Couchbase.AnalyticsClient" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Couchbase.AnalyticsClient --version 1.0.1
                    
#r "nuget: Couchbase.AnalyticsClient, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Couchbase.AnalyticsClient@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Couchbase.AnalyticsClient&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Couchbase.AnalyticsClient&version=1.0.1
                    
Install as a Cake Tool

<p align="center"> <img src="assets/couchbase-filled.png" alt="Couchbase" width="80" /> </p>

<h2 align="center">Couchbase Analytics .NET SDK</h2>

The official .NET SDK for Couchbase Analytics.

Install

Requires .NET 8.0.

dotnet add package Couchbase.AnalyticsClient

Documentation

Quick start

Connect

Create a Cluster with a connection string and Credential. The connection string supports http or https, multiple hosts, and query/timeout/TLS parameters.

using Couchbase.AnalyticsClient;
using Couchbase.AnalyticsClient.HTTP;
using Couchbase.AnalyticsClient.Options;

var credential = Credential.Create("username", "password");

var cluster = Cluster.Create(
    connectionString: "https://analytics.my-couchbase.example.com:18095?max_retries=5",
    credential: credential,
    configureOptions: options => options
        .WithTimeoutOptions(timeoutOpts => timeoutOpts
            .WithQueryTimeout(TimeSpan.FromSeconds(15)))
        .WithSecurityOptions(securityOpts => securityOpts
            .WithTrustOnlyCapella())
);

Use http://host:8095 for non-TLS connections, https://host:18095 for TLS (or your own custom ports for a load balancer or proxy)

If multiple IP addresses are resolved for a host, a connection will be attempted for a random one. If that connection attempt fails, another IP will be picked to attempt a connection, until all are exhausted.

Connection string parameters include:

  • timeout.connect_timeout, timeout.dispatch_timeout, timeout.query_timeout
  • security.trust_only_pem_file, security.disable_server_certificate_verification, security.cipher_suites
  • max_retries

Query

Run an Analytics statement and stream rows:

Results are streamed by default. Use QueryOptions.WithAsStreaming(false) to get a blocking result.

using Couchbase.AnalyticsClient.Options;

var result = await cluster.ExecuteQueryAsync(
    "SELECT i from ARRAY_RANGE(1, 100) AS i;",
    new QueryOptions()
        .WithReadOnly(true)
        .WithScanConsistency(QueryScanConsistency.RequestPlus)
).ConfigureAwait(false);

await foreach (var row in result.ConfigureAwait(false))
{
    Console.WriteLine(row.ContentAs<JsonElement>());
}

Query with parameters

var statement = "SELECT * FROM `travel-sample`.inventory.airline WHERE country = $country LIMIT $limit";

var paramResult = await _analytics2Fixture.Cluster.ExecuteQueryAsync(
    statement,
    new QueryOptions()
        .WithNamedParameter("country", "United States")
        .WithNamedParameter("limit", 10)
).ConfigureAwait(false);

await foreach (var row in paramResult.ConfigureAwait(false))
{
    Console.WriteLine(row.ContentAs<JsonElement>());
}   

/** Output:
{"airline":{"id":"airline_19433","type":"airline","name":"XAIR USA","iata":"XA","icao":"XAU","callsign":"XAIR","country":"United States"}}
...
*/

Database and scope context

Target a specific database and scope using Database(...).Scope(...).ExecuteQueryAsync(...):

var db = cluster.Database("travel-sample");
var scope = db.Scope("inventory");

var scoped = await scope.ExecuteQueryAsync(
    "SELECT id FROM airline LIMIT 5"
).ConfigureAwait(false);

await foreach (var row in scoped.ConfigureAwait(false))
{
    Console.WriteLine(row.ContentAs<JsonElement>());
}

/** Output:
{"id":"airline_19433"}
{"id":"airline_137"}
{"id":"airline_18239"}
{"id":"airline_10123"}
{"id":"airline_19290"}
*/

Options

Option classes are immutable records. Each mutation returns a new instance of the options.

Initialize, or modify options using:

With methods return a new instance of the options, to allow chaining:

var options = new QueryOptions()
    .WithReadOnly(true)
    .WithScanConsistency(QueryScanConsistency.RequestPlus);

Or use the initializer syntax:

var options = new QueryOptions()
{
    ReadOnly = true,
    ScanConsistency = QueryScanConsistency.RequestPlus
}

// or

options = options with {
    ReadOnly = true,
    ScanConsistency = QueryScanConsistency.RequestPlus
}

Cleanup

Cluster implements IDisposable. Dispose when done to release resources:

cluster.Dispose();

License

Apache 2.0, see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 102 10/8/2025