Couchbase GoLang客户端找不到存储桶

我有一个TCP服务器,尝试使用go-couchbase客户端库连接到Couchbase数据库,但是我得到了一个 错误消息,我尝试访问的存储桶名为“事件”,不存在。 </ p>

当我使用Go的官方Couchbase客户端库时,一切正常。</ p>

我注意到这两个客户端之间的区别是“ 池”。 我已将此池设置为“默认”。</ p>

什么可能导致该Go客户端看不到我的存储桶?</ p>

  cb,  err:= couchbase.Connect(“ http:// address:port”)
if err!= nil {

cbPool,err: = cb.GetPool(“ default”)
if err!= nil {

cbBucket,err:= cbPool.GetBucketWithAuth(“ events “,”用户名“,”密码“)
if err!= nil {
</ code> </ pre>
< / DIV>



I have a TCP server that tries to connect to a Couchbase database using the go-couchbase client library but I get an error saying that the bucket that I'm trying to access, named "events", doesn't exist.

When I use the official Couchbase client library for Go everything works fine.

The difference that I noticed between these two clients is the concept of "pool". I have set this pool to be "default".

What could lead to this Go client not seeing my bucket?

cb, err := couchbase.Connect("http://address:port")
if err != nil {
        log.Fatalf("Error connecting:  %v", err)

cbPool, err := cb.GetPool("default")
if err != nil {
    log.Fatalf("Error getting pool: %v", err)

cbBucket, err := cbPool.GetBucketWithAuth("events", "username", "password")
if err != nil {
    log.Fatalf("Error getting bucket: %v", err)


我假设您遇到某种身份验证错误。 该API有点令人困惑。 GetBucketWithAuth应该这样调用:</ p>

GetBucketWithAuth(“ events”,“ events”,“ password”)</ p>

原因是客户端希望 存储桶用户名和存储桶密码。 存储桶用户名与存储桶名称相同。</ p>

话虽如此,我强烈建议您使用gocb而不是go-couchbase。 gocb是官方的Couchbase go客户端,go-couchbase仅在Couchbase内部使用。 实际上,许多使用go-couchbase的组件将开始使用gocb代替,因为该库更易于使用并且组织得更好。</ p> </ p>
</ div>



I'm assuming you're getting some kind of an authentication error. The API is a little bit confusing. GetBucketWithAuth should be called like this:

GetBucketWithAuth("events", "events", "password")

The reason is that the client wants the bucket user name and the bucket password. The bucket username is the same as the bucket name.

With that said I would highly recommend that you use gocb and not go-couchbase. gocb is the official Couchbase go client and go-couchbase is only used internally inside Couchbase. In fact many of the components that use go-couchbase will start using gocb instead since this library is much easier to use and is better organized.

Csdn user default icon