However I’m unable to get my code to build because I can not seem to find the right assembly to resolve the GetBucket method.
This is what I have in my controller:
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ContractManagement.svc.Models;
using ContractManagement.svc.Interfaces;
using Couchbase;
using Couchbase.Management;
using Couchbase.Extensions;
using Couchbase.AspNet;
In my startup I have the following:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddCouchbase(Configuration.GetSection(“Couchbase”));
services.AddCouchbaseBucket("");
}
the interface is defined per the blog referenced above:
using Couchbase.Extensions.DependencyInjection;
namespace ContractManagement.svc.Interfaces
{
public interface ICMDBBucketProvider : INamedBucketProvider
{
// nothing goes here
}
}
What am I missing to get this last referenced method resolved?
That blog post is referring to old versions of Couchbase.Extensions.DependencyInjection and the Couchbase .NET SDK.
If you are using the latest version instead, I’d recommend checking out the documentation - Managing Connections using the .NET SDK with Couchbase Server | Couchbase Docs, especially if you are using the .NET SDK 3. The method you want is probably GetBucketAsync("bucketName") or GetBucketAsync() if you are using a named bucket provider.
Thank you for the clarification on that.
While I don’t see it in the docs you referenced. Do I attach the username and password as part of the query string for the couchbase server, using those words?
That is where you configure Couchbase in DI and provide the connection string, username, and password. In the above example, it will look at appsettings.json for a section of JSON like this:
I’ve made your suggested changes but I’m still not able to get this to work. Now when I try to preform GetBucketAsync() the system just seems to hang. No errors or exceptions are being displayed, nor does it seem to timeout. Please note my instance of couchbase is not running on my local but in a container in Azure.
Also, since you mentioned accessing a non-local cluster, it’s possible the networking setup may not be configured. Check out sdk-doctor to see if it finds any issues: SDK Doctor | Couchbase Docs
But we cant use the GetBucketAsync method in the constructor. So how do we inject the named provider and create a bucket and how do we run the N1QL queries? Any example of that would be great
Thanks a lot:)
This is entirely different from the SDK 2.x. In the 2.x version we used to inject the provider and create the bucket in the Constructor and run the N1QL queries at the bucket level. So we need to now know the clusters on which the query needs to run. Previously we just need to know the bucket on which the query needs to execute. Is my understanding correct?
How do we configure the clusters using Dependency Injection. It is a bit weird, the upsert is at bucket level, the get document is at bucket level. Only the N1Ql queries need to be run at cluster level.
There is a cluster object inside the bucket. I just used that property for my n1ql queries, and preformed key-value and subqueries using the bucket. Depending on your situation you can get better performance using these other types of queries.