Issues creating a scope with Go SDK

I have tried to use the CreateScope function.
I have Couchbase running as a docker container with the host port as 6091.
When I run this snippet to connect, it does not return an error:

cluster, err := gocb.Connect(
		"localhost",
		gocb.ClusterOptions{
			Username: "Administrator",
			Password: "qwerty",
		})
	if err != nil {
		panic(err)
	}

	bucket := cluster.Bucket("travel-sample")

However, this snippet to create a scope does not work:

func getCollectionsManager(bucket *gocb.Bucket) *gocb.CollectionManager {

    return bucket.Collections()
}

bucket := cluster.Bucket("travel-sample")
 cm := getCollectionsManager(bucket)

err = cm.CreateScope(scope_name,nil)
  if err != nil {
            panic(err)
   }

This results in the following error:

panic: Post "http://localhost:8091/pools/default/buckets/travel-sample/scopes": dial tcp [::1]:8091: connect: connection refused

I’m not sure how to fix this so any leads would be appreciated!
Thanks!

Hi @aditi can you tell us which version of SDK and Server are you current running your code against ?

@AV25242 I am using the latest stable version of the SDK(installed github.com/couchbase/gocb/v2
) and a docker container running Couchbase Server 7.0.0.

Hi @aditi the connection refused definitely points to a connectivity issue. You say

I have Couchbase running as a docker container with the host port as 6091.

Was this a typo or have you actually opened 6091 rather than 8091 (which is the port we’d typically expect to see open)?

As a couple of sidenotes - Connect will not return an error if there is an issue with connectively, it only returns an error if there’s an issue validating the settings that you’ve provided (e.g. you’ve used something like notarealscheme://localhost). You can use WaitUntilReady to verify that the SDK can connect to your cluster although it’ll only tell you that it can’t connect (via a timeout error) rather than why. To try get an idea of what the SDK thinks is going on you can enable logging.

@chvck I am running it on 6091. I have mapped container port 8091 to host port 6091 and hence, I access the CB UI at localhost:6091.

Could you point me to some examples of connecting to a CB cluster on a non-8091 port? I could refer to those and find my error.

Thanks!

Hi @aditi I’m not that well versed on using docker but I’m not sure this will actually work. The SDK actually bootstraps over the memcached protocol i.e. port 11210 which from the looks of that port mapping should be ok.

The problem is going to be that it looks like Couchbase Server is actually running the management port at 8091 but then you’re mapping it to 6091. Couchbase Server won’t know about your mapping to 6091 and so will be advertising to the SDK that it’s running the management port on 8091, the same is true of the other HTTP 80xx ports that you’re mapping to 60xx.

I’m not 100% sure but I think you might need to setup alternate addresses.