Retrieve Couchbase version from .NET client

Given an instance of IBucket, I’m wondering if there is any way to retrieve the version of Couchbase that is running in the cluster. There is a Cluster object in the bucket instance, of course, but I could not find any values representing anything like “6.6.2” or “7.0.2”.
We are needing to identify the server version for use in a conditional statement. I.e.
if (version == "7.0.2") { //do something special }


There is a way, I just don’t think it’s documented. But we use it to support some external libraries like Linq2Couchbase.

var versionProvider = cluster.ClusterServices.GetRequiredService<IClusterVersionProvider>();
var clusterVersion = await versionProvider.GetVersionAsync();

More info here: couchbase-net-client/IClusterVersionProvider.cs at master · couchbase/couchbase-net-client · GitHub

Some notes:

  • It will return null if it is unable to acquire the version for any reason, but errors will be logged.
  • The result is cached for the lifetime of the cluster or until ClearCache is called. So if you do a rolling upgrade of your cluster, your app will still think it’s on the old version until recycled or you call ClearCache.
  • If your cluster is in a mixed-version mode during an upgrade, the lowest version is returned.