riorio
riorio

Reputation: 6816

Swapping buckets in Couchbase

Following an exact question about MySQL tables swap, I like to do the same operation in Couchbase's server buckets.

For example, given buckets of:

foo and foo_new

I like to swap the names to:

foo_old and foo

The MySQL equivalent command is: RENAME TABLE foo TO foo_old, foo_new To foo;

In addition, I like to make this change via Java SDK and not manually.

I found this old post that states that it is not possible to change bucket name.

Is it possible in newer version? Till now I was not able to find something that can do it.

Upvotes: 2

Views: 155

Answers (1)

Johan Larson
Johan Larson

Reputation: 1890

There is no N1QL command for renaming buckets. None are planned, either. Since you cannot change the name of a bucket from the UI, it's safe to say there isn't an API for doing this, either.

You would have to use an API command to create a new bucket, a bunch of N1QL commands to create new indexes on the new bucket, and then copy over all the documents from the old bucket to the new, presumably using an INSERT-SELECT.

Unless you are using very small buckets, probably for test purposes, I don't recommend this approach.

Upvotes: 3

Related Questions