mongoexport --fields --csv will only output the first field when working with subdocuments

Cilvic picture Cilvic · Sep 22, 2013 · Viewed 17.3k times · Source

Working:

 .\mongoexport.exe --db mydb --collection slideproof_user_event_date_count --csv --out 
events.csv --fields '_id,first_day'
 .\mongoexport.exe --db mydb --collection slideproof_user_event_date_count --out 
events.json --fields '_id._p,first_day'

Not working (only first field/column has content) written, :

 .\mongoexport.exe --db mydb --collection slideproof_user_event_date_count --csv --out 
events.csv --fields '_id._p, first_day'

How can I enable correct output for .csv with subdocument fields?

Answer

Cilvic picture Cilvic · Sep 22, 2013

The solution is to avoid spaces in the --fields argument:

this works:

--fields '_id._p,value.count'

This does not:

--fields '_id._p, value.count'