Mongoexport of array values in CSV format

111 views
Skip to first unread message

sekhar reddy

unread,
Nov 16, 2017, 11:06:01 AM11/16/17
to mongodb-user
I want to know is there any possibility to Export all the array values without giving index number while exporting (to csv).

E.g : In general we use some like this 

mongoexport -d Employee -c Employee --type=csv --out Emp_Mongo.csv --fields Address.0.contact.0.Phone,Address.0.contact.0.Email

But if don't know the array size, it will be difficult to Export all the array values.

There is one more option i.e. $unwind . i have tried that already.

But wanted to know is there any possibility without giving index number and Export all the array data in csv format

something like
Address.$.contact.$.Phone??

Kevin Adistambha

unread,
Nov 26, 2017, 11:32:09 PM11/26/17
to mongodb-user

Hi

But wanted to know is there any possibility without giving index number and Export all the array data in csv format

Did I understand correctly that you wanted to export e.g. this document:

{_id: "xyz", field1: "x", field2: [ {a: 1, b: 2, c: 3} ] }

into its CSV representation?

I’m not aware of a method to do so using mongoexport, since the two representations are quite different (the MongoDB representation is a document, and the CSV representation is tabular). Without precise information on how to “unwind” the document into its tabular form, mongoexport cannot know how you want your data to be represented.

Alternatively, you might be able to create a temporary collection such as using the aggregation framework’s $out stage to craft the representation that can be exported easily by mongoexport.

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages