I need to create bucket and indexes using code. I tried with CreateBucketAsync method but it ask for 'ManagemenUri' in cluster object and my cluster object don't have it. I have observed that ManagementUri appears in cluster object only after doing a BucketAsync. so please can you advice how to create a bucket in c#?
await cluster.Buckets.CreateBucketAsync(bucketSettings);
In order to use the Bucket management API, you'll need to open a connection to Couchbase which will then populate the ManagementUri internally. For example:
var cluster = await Cluster.ConnectAsync("couchbase://localhost", _options);
var bucketManager = cluster.Buckets;
await bucketManager.CreateBucketAsync(//your settings here//);
The "management uri" which is used internally to post the request is derived from the server cluster config fetched from the server when you call ConnectAsync.
That being said, I suspect that your doing this and then encountering a NulReferenceException that points to the ManagementUri? If this is the case the connection to the server never successfully happened and you are seeing a side effect of this (which is the incorrect error message).
I would verify that the connection is correctly being made. You can do this by enabling logging and then checking to see how the bootstrapping went. Additionally, I created a Jira ticket for improving the error message here so that its easier to understand why its failing.