Yes! In fact, if you’ve done this sort of thing in SQL, then you are not too far from already knowing the answer.

Fire buckets Image Licensed through Creative Commons via Paul Harrop

There are command line tools to backup/restore a bucket, but for this post, I’m going to assume that what you want is to make a copy of some documents from bucket A into bucket B.

It’s as easy as using a N1QL INSERT.

Start by creating a N1QL SELECT to get the documents you want out of the first bucket. I’m going to show a very simplified SELECT that gets all the documents from my default bucket. If you only want a subset, you can use a WHERE clause.

SELECT META().id _k, _v from `default` _v 1 2 SELECT META ( ) . id _k , _v from ` default ` _v

Since we’re copying to another bucket, we need both the key and the document itself. This query selects the document key using the META() function, and selects the document using a _v alias.

Next, I’ll create an INSERT to put these selected documents into another bucket, which I called target .

INSERT INTO `target` (KEY _k, VALUE _v) SELECT META().id _k, _v from `default` _v 1 2 3 INSERT INTO ` target ` ( KEY _k , VALUE _v ) SELECT META ( ) . id _k , _v from ` default ` _v