How to export all collections in MongoDB?

前端 未结 28 1548
你的背包
你的背包 2020-11-29 14:32

I want to export all collections in MongoDB by the command:

mongoexport -d dbname -o Mongo.json

The result is:
No collection specifie

28条回答
  •  萌比男神i
    2020-11-29 14:47

    I found after trying lots of convoluted examples that very simple approach worked for me.

    I just wanted to take a dump of a db from local and import it on a remote instance:

    on the local machine:

    mongodump -d databasename
    

    then I scp'd my dump to my server machine:

    scp -r dump user@xx.xxx.xxx.xxx:~
    

    then from the parent dir of the dump simply:

    mongorestore 
    

    and that imported the database.

    assuming mongodb service is running of course.

提交回复
热议问题