If you want to export any collections of any of your mongodb database, you can use mongoexport
command. For example:
mongoexport --db dbname --collection collectionName --query '{"fields":1}' --out output.json
However, if you add any of selection criteria to the query, mongoexport
command doesn't work. For example, if you run the following command:
mongoexport --db dbname --collection collectionName --query '{},{"fields":0}' --out output.json
the resultant JSON file includes data of every field, despite me excluding a filed named fields
.
So why does this such strange behavior occur? And how can I fix it?
For your information, db.colName.find({},{"fields":0})
in mongoDB shell works as usual.
I'm on MongoDB 2.4.3 and OS X 10.9.
Thanks.
mongoexport is a command-line tool that produces a JSON or CSV export of data stored in a MongoDB instance. mongodump is a utility for creating a binary export of the contents of a database.
Export MongoDB to CSV (e.g. Excel) Open the Export Wizard and select your export source. This screen only appears if you haven't chosen an item in the Connection Tree, run a previous query, or selected specific documents. Next, choose CSV as the export format then click Next.
The mongoexport tool exports data in Amazon DocumentDB to JSON, CSV, or TSV file formats.
That's because --query
argument takes only query and there is no option to pass projection. See mongoexport --query
in official documentation. If you want to use a projection you have to add --fields
option
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