Not able to retrive any data using gocb v2 sdk with couchbase 6.0.1 server

Hi @kapil, just a further note to the detail that @AV25242 has added - it’s not possible to tell from from your example so just to be clear. Against a 6.0.x cluster you need to first open a bucket before you can use cluster.Query. Even though you aren’t necessarily using the bucket the cluster.Bucket call is where the connection becomes available for queries against server versions prior to 6.5. Server 6.5+ supports querying without requiring a bucket level connection.

Also just a quick note on:

rows, err := GetCluster().Query(n1ql, &gocb.QueryOptions{})
rows.Row(&tempDoc)
defer rows.Close()
if err != nil {
	logrus.Info("In func: "+funcName+",error..", err)
	return false, ""
}

You should check the value of err before accessing rows. If any error is returned then rows will be nil and you will encounter a panic. i.e.:

rows, err := GetCluster().Query(n1ql, &gocb.QueryOptions{})
if err != nil {
	logrus.Info("In func: "+funcName+",error..", err)
	return false, ""
}
...
1 Like