Error Details
System.AggregateException
HResult=0x80131500
Message=Cluster has not yet bootstrapped. Call WaitUntilReadyAsync(…) to wait for it to complete.
Source=System.Private.CoreLib
StackTrace:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Threading.Tasks.ValueTask1.get_Result() at System.Runtime.CompilerServices.ValueTaskAwaiter
1.GetResult()
at CouchBaseDemo.Program.d__0.MoveNext() in D:\Web Applications\CouchBaseDemo\Program.cs:line 63
Code:
class Program
{
static async Task Main(string args)
{
// Update this to your cluster
var endpoint = “couchbases://cb.y-q7gd97sckygoqr.cloud.couchbase.com”;
var username = “username”;
var password = “password”;
var bucketName = “travel-sample”;
var scopeName = “inventory”;
var collectionName = “airport”;
// Sample airline document
var key = “airline_8091”;
var content = new JObject
{
{ “type”, “airline” },
{ “id”, 8091 },
{ “callsign”, “CBS” },
{ “iata”, null },
{ “icao”, null },
{ “name”, “Couchbase Airways” }
};
var clusterOptions = new ClusterOptions
{
UserName = username,
Password = password
};
clusterOptions.ApplyProfile(“wan-development”);
var cluster = await Cluster.ConnectAsync(endpoint, clusterOptions);
//await cluster.WaitUntilReadyAsync(TimeSpan.FromSeconds(10));
//await cluster.WaitUntilReadyAsync(new TimeSpan(0, 2, 0));
var bucket = await cluster.BucketAsync(bucketName);
// Wait until the bucket is ready for use
await bucket.WaitUntilReadyAsync(TimeSpan.FromSeconds(10));
// Get the reference to the scope
var scope = await bucket.ScopeAsync(scopeName);
// Get a reference to our collection
var collection = await scope.CollectionAsync(collectionName);
// Simple KV operation - to create a document with specific ID
try
{
var mutationResult = await collection.InsertAsync(key, content);
Console.WriteLine($“Create document success. CAS: {mutationResult.Cas}”);
}
catch (CouchbaseException ex)
{
Console.WriteLine(ex);
return;
}
// Simple KV operation - to retrieve a document by ID
JObject result = null;
try
{
result = (await collection.GetAsync(key)).ContentAs();
Console.WriteLine($“Fetch document success. Result: {result.ToString()}”);
}
catch (DocumentNotFoundException ex)
{
Console.WriteLine(ex);
return;
}
// Simple KV operation - to update a document by ID
try
{
result[“name”] = “Couchbase Airways!!”;
var mutationResult = await collection.ReplaceAsync(key, result);
Console.WriteLine($“Update document success. CAS: {mutationResult.Cas}”);
}
catch (CouchbaseException ex)
{
Console.WriteLine(ex);
return;
}
// Simple K-V operation - to delete a document by ID
try
{
await collection.RemoveAsync(key);
Console.WriteLine(“Delete document success.”);
}
catch (DocumentNotFoundException ex)
{
Console.WriteLine(ex);
}
}
}