Prakash Thapa
Prakash Thapa

Reputation: 1285

How to rename a bucket in couchbase?

I have a bucket name 0001 when I use the following N1QL statement I get a "5000" syntax error:

cbq> Select * from 0001;
{
    "requestID": "f2b70856-f80c-4c89-ab37-740e82d119b5",
    "errors": [
        {
            "code": 5000,
            "msg": "syntax error"
        }
    ],
    "status": "fatal",
    "metrics": {
        "elapsedTime": "349.733us",
        "executionTime": "204.442us",
        "resultCount": 0,
        "resultSize": 0,
        "errorCount": 1
    }
}

I think it takes 0001 as a number and not as a bucket name, is there an easy way to rename it?

Upvotes: 3

Views: 2204

Answers (2)

NoSQLKnowHow
NoSQLKnowHow

Reputation: 4855

There is no way I am seeing to rename. I checked the CLI as well and nothing. Your best bet, if you can, is to create a new bucket with the settings you want and then use cbtransfer to move the data over from the old to the new bucket. This is an online operation.

Upvotes: 2

geraldss
geraldss

Reputation: 2445

In this case you can use back ticks in N1QL to escape the bucket name:

cbq> Select * from `0001`;
{
    "requestID": "f48527e6-6035-47e7-a34f-90efe9f90d4f",
    "signature": {
        "*": "*"
    },
    "results": [
        {
            "0001": {
                "Hello": "World"
            }
        }
    ],
    "status": "success",
    "metrics": {
        "elapsedTime": "2.410929ms",
        "executionTime": "2.363788ms",
        "resultCount": 1,
        "resultSize": 80
    }
}

Currently there is noway to rename a bucket instead you could do one of the following:

  1. Backup the bucket using cbbackup. Then recreate it and restore it using cbrestore.
  2. Create a second cluster and use XDCR to transfer the data to the new cluster with the correctly named bucket.

Upvotes: 5

Related Questions