How to import/export all collections of the MongoDB database using mongodb java driver?

一世执手 提交于 2019-11-30 09:33:52

问题


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.


回答1:


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




回答2:


(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).




回答3:


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 <>..");



回答4:


mongodump --host localhost --port 27017 --db sample    

It exacts with folder as dump with database name sample

mongorestore --db sample --verbose d:/dump/sample/


来源:https://stackoverflow.com/questions/33492008/how-to-import-export-all-collections-of-the-mongodb-database-using-mongodb-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!