How to get mongo command results in to a flat file

后端 未结 8 2088
攒了一身酷
攒了一身酷 2021-01-30 06:26

How do I export the results of a MongoDB command to a flat file

For example, If I am to get db.collectionname.find() into a flat file.

I tried

8条回答
  •  庸人自扰
    2021-01-30 07:25

    I know of no way to do that from the mongo shell directly, but you can get mongoexport to execute queries and send the results to a file with the -q and -o options:

    mongoexport -h mongo.dev.priv -d models -c profiles -q '{ $query : { _id : "MRD461000" } }' -o MRD_Series1.json
    

    The above hits queries the profiles collection in the models database grabbing the JSON document for _id = "MRD641000". Works for me.

提交回复
热议问题