Connecting to couchbase cluster without bucket name using C SDK


Is there a way to connect to couchbase cluster without using the bucket name.
I tried below approach, but its not working.

Basically I need to do a cluster authentication during my application startup, during which I do not have any bucket name information. The only details available is username/password and cluster node.

The weird thing is, even when I commented the options.v.v3.connstr line, the below runs without any login errors.

// Code

lcb_t instance;
lcb_create_st options;
memset(&options, 0, sizeof options);
options.version = 3;
options.v.v3.type = LCB_TYPE_CLUSTER;
options.v.v3.connstr = "couchbase://localhost";
options.v.v3.username = "username";
options.v.v3.passwd = "password";
lcb_error_t rc = lcb_create(&instance, &options);
if(rc != LCB_SUCCESS)
   fprintf(stderr, "Error creating instance\n");

rc = lcb_connect(instance);
if(rc != LCB_SUCCESS)
   fprintf(stderr, "Error in connect \n");

if ((rc = lcb_get_bootstrap_status(instance)) != LCB_SUCCESS)
   fprintf(stderr, "Error in login:%s \n", lcb_strerror(NULL, rc));
   return -1;
   fprintf(stderr, "Connection succesfull\n");

You cannot use lcb_t without bucket information for data acces. In your case, just do not create lcb_t that early at all, and initialize new connection as soon as you need it and have bucket name.

Cluster mode might defer credentials check until your cluster-level operation.

1 Like