Couchbase GoLang客户端找不到存储桶

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

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

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

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

  cb,  err:= couchbase.Connect(“ http:// address:port”)
if err!= nil {
log.Fatalf(“连接错误:%v”,err)
}

cbPool,err: = cb.GetPool(“ default”)
if err!= nil {
log.Fatalf(“获取池时出错:%v”,err)
}

cbBucket,err:= cbPool.GetBucketWithAuth(“ events “,”用户名“,”密码“)
if err!= nil {
log.Fatalf(”获取存储区时出错:%v“,err)
}
</ 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)
}

1个回答



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

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

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

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

https://github.com/couchbase/gocb </ 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.

https://github.com/couchbase/gocb

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问