Reputation: 636
I am new to MongoDB. I want to export some fields to csv file and if that field is present in particular row then I want empty value in that field. Currently I am trying this:
mongoexport --host hostname --collection collectionname -q '{}' -f "field1","field2" --db dbname --username user --password pass --out out.csv
But problem is that output does not keep the field if field value is not present in the database. Any suggestion how can I perform the desired operation?
Upvotes: 1
Views: 489
Reputation: 2989
Try:
mongoexport --host hostname --username user --password pass --db dbname --collection collectionname --type=csv --fields field1,field2 --query '{field1: { $exists: true}, field2: { $exists: true}}' --out out.csv
For more detail: Click here
Upvotes: 1