[mongodb] How to export mongodb data as CSV
How to export mongodb data as CSV
Prerequisite
install mongoexport
Sample code:
export data that invoice_date in July, 2023:
mongoexport --host "{host}" --type=csv --authenticationDatabase admin -u admin -p {pwd} -d dashboard -c 'paymentRecords2' --query='{ "$or": [{"invoice_date": { "$gte": 1688169600, "$lt": 1690848000 } },{ "actual_payment_date": { "$gte": 1688169600, "$lt": 1690848000 } } ]}' -o "mongodb_export_paymentRecords2.csv" --fields _id,field1,field2,field3
Note:
- --fields should not contain space
留言
張貼留言