MongoDB Java驱动程序中是否有可能制作备份和还原数据库?
我的解决方案(只需执行命令)现在:
public void makeBackUp(String path) {
try {
Runtime.getRuntime().exec("mongodump --out " + path);
} catch (IOException ex) {
Logger.getLogger(MongoDB.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void restore(String backUpPath) {
try {
Runtime.getRuntime().exec("mongorestore " + backUpPath);
} catch (IOException ex) {
Logger.getLogger(MongoDB.class.getName()).log(Level.SEVERE, null, ex);
}
}
提前致谢.
解决方法:
到目前为止,简短的回答是“否”.这些命令只能从命令行调用.您可能会考虑从所有集合中获取所有数据,但预期速度会很慢.您可以阅读有关此here的讨论
标签:mongodb,mongo-java-driver,java
来源: https://codeday.me/bug/20191118/2027846.html