How to export collection to CSV in MongoDB?

前端 未结 11 1594
刺人心
刺人心 2020-12-12 11:52

How do you export all the records in a MongoDB collection to a .csv file?

mongoexport --host localhost --db dbname --collection name --type=csv          


        
11条回答
  •  旧时难觅i
    2020-12-12 12:14

    Solution for MongoDB Atlas users!

    Add the --fields parameter as comma separated field names enclosed in double inverted quotes:

    --fields ",..."
    

    This is complete example:

    mongoexport --host Cluster0-shard-0/shard1URL.mongodb.net:27017,shard2URL.mongodb.net:27017,shard3URL.mongodb.net:27017 --ssl --username  --password  --authenticationDatabase admin --db  --collection  --type  --out  --fields ",..."
    

提交回复
热议问题