Need to Alias the header name in the Mongoexport CSV file

977 views
Skip to first unread message

Anand Mohan

unread,
Aug 10, 2017, 1:32:30 AM8/10/17
to mongodb-user
Hi All,

I need to alias the name for the header in the mongoexport CSV file . Is there any way we can rename the header of the exported CSV file

Example:

{
 "id":1,
 "words":["data","base"]
}

My file would be as:
id
words.0
But i need like :

id
first_word




regards,
Anand Mohan G

Wan Bachtiar

unread,
Aug 15, 2017, 1:55:13 AM8/15/17
to mongodb-user

Is there any way we can rename the header of the exported CSV file

Hi Anand,

If you’re asking whether you could rename the headers field name while exporting using mongoexport,
 currently (MongoDB v3.4.x) there is no such feature to do so. 

Depending on your use case and if you’re using MongoDB v3.4.x, you could create a read-only Views of the collection. As Views are created using MongoDB Aggregation Pipeline, you could utilise $project to rename your field(s) or apply other document transformations.

Alternatively, as the CSV header is normally the first line of the file, you may be able to utilise other command line tools to replace the first line after the export. For example using sed sed '1 s/words.0/first_word/' example.csv

Regards,

Wan.

Reply all
Reply to author
Forward
0 new messages