3

I need to export the data that I have in Azure CosmosDB table to a CSV file.

I tried to use ADF but I only found configured for SQL and MongoDB and I am using TABLE STORAGE in COSMOSDB options .

Is there an easy or coded way to achieve this?

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
Cesar Castillo
  • 147
  • 1
  • 4
  • 11

3 Answers3

4

I found a way to export Azure data from CosmosDB table to a CSV file.

From what I found there is no way to export the data directly from the azure web portal but from Azure Storage Explorer It is free and supported by Microsoft. Browse to the appropriate storage account, click on the table storage you want to export and look for the export option in the explorer.

I still have a code tool pending to solve this and make it more automatic

enter image description here

Cesar Castillo
  • 147
  • 1
  • 4
  • 11
2

I think I can share this answer with you. Because I haven't found any docs to describe a solution to export data from cosmosdb table api.

First, it mentioned a tool which is not free and provides download data as csv file.

enter image description here

And along the idea of writing code to achieve exporting data feature. I think it's also realizable for cosmosdb. You can query all the items you wanted and write them in csv file. Share a high voted answer here and it recommend to use the library CsvHelper, I think it's helpful to use File.WriteAllText(filePath, csv.ToString());

Tiny Wang
  • 10,423
  • 1
  • 11
  • 29
0

I wrote a small library built on the new Azure.Data.Tables SDK to get Azure Storage Explorer compatible CSV exports.With that you can export to CSV file or to Azure BLOB Storage in a few lines of code and use it for example in Azure Storage. Note that it currently loads all data in memory though to create the proper CSV headers.

// Export all rows from the table to a CSV file
using StreamWriter writer = File.CreateText("test.csv");
await _tableClient.ExportCSVAsync(writer);

// Export all rows as CSV to Azure BLob Storage
BlobContainerClient containerClient = new(BlobConnectionString, "testcontainer");
var blobClient = containerClient.GetBlobClient("test.csv");
var stream = await blobClient.OpenWriteAsync(true, new BlobOpenWriteOptions() { HttpHeaders = new BlobHttpHeaders { ContentType = "text/csv" } });
using StreamWriter writer = new(stream);
await _tableClient.ExportCSVAsync(writer);

Thomas
  • 4,030
  • 4
  • 40
  • 79