MongoシェルでMongoexportコマンドを使用してコレクション全体をエクスポートできます。JavaプログラムでMongoExportコマンドを使用するには?
しかし、私はMongoexportコマンドを使ってMongoDBのコレクション全体をCSVファイルにエクスポートするJavaプログラムを作成しようとしています。
マイコード:私はにjava.io.IOExceptionが直面しているよ
public class MongoExportSample {
public static void main(String[] args) {
String db = "pack";
String col = "col";
String Host="localhost";
String Port="27017";
String fileName = "D:/user/sample.csv";
String command = "mongoexport --host Host --port Port --db " + db + " --collection " + col + " --csv --out " + fileName + "";
try {
Process process=Runtime.getRuntime().exec(command);
int waitFor = process.waitFor();
System.out.println("waitFor:: "+waitFor);
BufferedReader success=new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader error=new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s="";
while ((s = success.readLine()) != null) {
System.out.println(s);
}
while ((s = error.readLine()) != null) {
System.out.println("Std ERROR : " + s);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
:プログラムを実行することはできません "mongoexport":CreateProcessをエラー= 2、システムは指定されたファイルを見つけることができません。
誰が
Please check the screenshot for STDERR here
Mongo 3.4をお使いですか?エクスポートコマンドの構文を改善するだけです。 – notionquest
私はMongoを使用しています。3.2 – dev999