[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

留言

這個網誌中的熱門文章

Salesforce證照考試心得 (Administrator and Advanced Administrator)

ISC2 CC (Certified in Cybersecurity Certification) 考試心得

Visual Studio Code 常忘功能 VSC FAQ