Dump Mongo Collection into JSON format

后端 未结 5 878
小蘑菇
小蘑菇 2020-12-04 07:10

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.

5条回答
  •  心在旅途
    2020-12-04 07:49

    Mongo includes a mongoexport utility (see docs) which can dump a collection. This utility uses the native libmongoclient and is likely the fastest method.

    mongoexport -d  -c 
    

    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)

提交回复
热议问题