Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export from Couchbase to CSV file

I have a Couchbase Cluster with only one node (let's call it localhost) and I need to export all the data from a very big bucket (let's call it XXX) into a CSV file.

Now this seems to be a pretty easy task but I can't find the way to make it work.

According to the (really bad) documentation on the cbtransfer toold from Couchbase http://docs.couchbase.com/admin/admin/CLI/cbtransfer_tool.html they say this is possible but they don't explain it clearly. They just add a flag if you want the transfer to occur in csv format (?) but it is not working. Maybe someone who already did this can give me a hand?

Using the documentation I've been able to make an approach to the result I want to obtain (a clean CSV file with all the documents in the XXX bucket) using this command:

/opt/couchbase/bin/cbtransfer http://localhost:8091 /path/to/export/output.csv -b XXX

But what I get is that /path/to/export/output.csv is actually a folder with a lot of folders inside and it is storing some kind of json metadata that can be used to restore the XXX bucket in another instance of Couchbase.

Has anyone been able to export data from a Couchbase bucket (Json documents) into a CSV file?

like image 929
Jose Garrido Avatar asked Mar 22 '26 10:03

Jose Garrido


1 Answers

From looking at the documentation, you have to put a slightly different syntax to export to a CSV. http://docs.couchbase.com/admin/admin/CLI/cbtransfer_tool.html

It needs to look like so:

cbtransfer http://[localhost]:8091 csv:./data.csv -b default -u Administrator -p password

Notice the "csv:" before the name of the csv file.

I tested this and it does export a CSV. Just be forwarned that you need a relatively flat document structure for this to work really well, as JSON can represent far more complex data structures than CSV obviously, e.g. arrays, sub-documents, etc. cbtransfer will not unravel those. For example, if there is a subdocument, cbtransfer will represent it as a JSON doc in the line of each CSV.

So depending on what your document structure is, exporting to CSV is not an ideal format. It is a step backwards.

like image 125
Kirk Avatar answered Mar 25 '26 02:03

Kirk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!