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.
相关问题
- Jackson Deserialization not calling deserialize on
- MongoDB can not create unique sparse index (duplic
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Spring Data MongoDB - lazy access to some fields
相关文章
- mongodb有没有什么办法禁止读取数据的时候进行缓存
- mongodb-aggregate聚合查询分组后如何获得多字段
- json_encode 没有把数组转为json
- Livy Server: return a dataframe as JSON?
- mongodb error: how do I make sure that your journa
- How to track MongoDB requests from a console appli
- Unexpected end of JSON input from an ajax call
- How do I do a nested list (array) of schema refere
From the Mongo documentation:
Read more here: http://www.mongodb.org/display/DOCS/mongoexport
Here's mine command for reference:
On Windows 7 (MongoDB 3.4), one has to move the cmd to the place where
mongod.exe
andmongo.exe
file resides =>C:\MongoDB\Server\3.4\bin
else it won't work saying it does not recongnizemongoexport
command.If you want to dump all collections, run this command:
It will generate all collections data in
json
andbson
extensions into/tmp/{DB_NAME}
directoryMongo includes a mongoexport utility (see docs) which can dump a collection. This utility uses the native libmongoclient and is likely the fastest method.
Also helpful:
-o
: write the output to file, otherwise standard output is used (docs)--jsonArray
: generates a valid json document, instead of one json object per line (docs)--pretty
: outputs formatted json (docs)Use mongoexport/mongoimport to dump/restore a collection:
Export JSON File:
mongoexport --db <database-name> --collection <collection-name> --out output.json
Import JSON File:
mongoimport --db <database-name> --collection <collection-name> --file input.json
Also, http://bsonspec.org/