1.

"_id" : 1 "a" : 1 "c" : 1, "b" : 1, "a" : 1

Answer»

MongoDB provides several utilities for data movement activities like mongodump, mongoexport ETC. Mongodump is used to export the contents of the collection in an external file in the BSON(binary) format. The contents exported by this method can then be used by mongorestore command to restore in another database or different collection. Mongodump does not capture index data and only captures the data present in the backup. Since the contents are exported in binary format using this method we cannot use it for exporting to CSV file.

To export the contents in JSON or CSV format we can use the mongoexport command. The exported collection can then be RESTORED using mongoimport command. Since Mongoexport exports cannot export in BSON all the rich BSON data TYPES are not preserved while exporting the data. Due to this reason, mongoexport should be used with CAREFUL consideration.

Below is the command that can be used for the same.

mongoexport --host host:27017 -d test -C sample --type=csv -f fields -o sample.csv


Discussion

No Comment Found