Wednesday, 19 June 2013

Export MongoDB "Database" in JAVA

public class TempMongoExportDB {

public void mongoExport()
throws IOException {

String command = "mongodump -db tree -o c:\\backup";
Process p = Runtime.getRuntime().exec(command);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(
p.getInputStream()));

BufferedReader stdError = new BufferedReader(new InputStreamReader(
p.getErrorStream()));

// read the output from the command
String s = "";

while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}

while ((s = stdError.readLine()) != null) {
System.out.println("Std ERROR : " + s);
}

}

public static void main(String[] args) throws IOException {

TempMongoExportDB tempMongoExportDB = new TempMongoExportDB();
tempMongoExportDB.mongoExport();

}

}

Post a Comment