I want to export from mongodb where objectId will be converted to string when exporting.
ObjectId("507c7f79bcf86cd7994f6c0e").toString()
This does not work with export command. I tried the following but that showing syntax error.
./mongoexport --host localhost --db Database --collection collection_name --type=csv --out collection.csv --fields _id.toString()
How can I do this?
I don't think you can do this with a single command, but after running your export, you can use sed to convert to a string.
sed -i 's/ObjectId(\([[:alnum:]]*\))/\1/g' collection.csv
I got the pattern from here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With