I hope you can help me out and point me to the right direction.
The scenario is that I have two Couchbase buckets ‘source’ and ‘destination’ and I would like to transfer some documents to the destination bucket. The condition is to select and transfer only those documents containing instituionId:60
*NOTE: There will be several document of different type that has the institutionId field.
I already looked at some of the forums and blogs and tried the SELECT query using N1QL but I do not know how to transfer documents given the condition above?
During a Couchbase Day event we learned about a clever way to use XDCR (Cross Datacenter Replication) to transfer documents from one bucket to another. It is also possible to specify a filter condition. It is maybe kind of an abuse of this feature, but it is possible to move documents between buckets even within the same data center or same cluster.
I think you can do the same without much code by using sync gateway to sync gateway replication. For this in each document you can put instituionId in the channel and then use sync gateway to sync gateway replication.
If you need filter by the key of the document you can use all above options. However, is you want to filter using a field of the document you have to use the first one.
@Teix
Can you help provide the sample query based on the scenario that I posted? I tried some queries but I cannot transfer the documents where their institutionId=64
With below query you will copy all the documents (without changing the ID of the document neither the content of the JSON) from the beer-sample bucket where field brewery_id is 21st_amendment_brewery_cafe to a new bucket beer-sample-replica (you have to create first the second bucket).
INSERT INTO `beer-sample-replica` (KEY META().id)
SELECT *
FROM `beer-sample`
WHERE brewery_id='21st_amendment_brewery_cafe';
I hope this help you
UPDATE:
At the end of the section you will find some INSERT-INTO-SELECT examples