How to import/export all collections of the MongoD

2019-01-28 12:55发布

Is there any function to import and export all collections of mongodb database using java driver.? like there is mongodump and mongorestore using command prompt.

4条回答
家丑人穷心不美
2楼-- · 2019-01-28 13:33

The short answer is no. These commands can be invoked only from command line. You might consider to fetch all the data from all collections but its expected to be slow.

You can read the discussion around this here

Hope this helps

查看更多
Animai°情兽
3楼-- · 2019-01-28 13:44
mongodump --host localhost --port 27017 --db sample    

It exacts with folder as dump with database name sample

mongorestore --db sample --verbose d:/dump/sample/
查看更多
Fickle 薄情
4楼-- · 2019-01-28 13:51

Well as of now, Mongo Java driver does not support this.

You can try invoking the mongoimport and mongorestore commands from Java Runtime. Like

Runtime.getRuntime().exec("mongoimport -d <dbname> -h <>..");
查看更多
仙女界的扛把子
5楼-- · 2019-01-28 13:53

(same answer as here)

recently I've started a project called mongodbdump-java-wrapper to wrap mongodump.exe and mongorestore.exe mongodb executable from java.

You could clone it from : github project. This project includes integration tests (a way to know how implement backup/restore).

查看更多
登录 后发表回答