Is there any way to dump mongo collection into json format? Either on the shell or using java driver.I am looking for the one with best performance.
Use mongoexport/mongoimport to dump/restore a collection:
Export JSON File:
mongoexport --db
Import JSON File:
mongoimport --db
WARNING
mongoimportandmongoexportdo not reliably preserve all rich BSON data types because JSON can only represent a subset of the types supported by BSON. As a result, data exported or imported with these tools may lose some measure of fidelity.
Also, http://bsonspec.org/
BSON is designed to be fast to encode and decode. For example, integers are stored as 32 (or 64) bit integers, so they don't need to be parsed to and from text. This uses more space than JSON for small integers, but is much faster to parse.
In addition to compactness, BSON adds additional data types unavailable in JSON, notably the BinData and Date data types.