How can I import data to Mongodb from Json file using java

后端 未结 7 814
梦如初夏
梦如初夏 2021-01-05 00:59

I am struggling with importing data into Mongodb from a Json file.
I can do the same in command line by using mongoimport command.

7条回答
  •  抹茶落季
    2021-01-05 01:41

    Runtime r = Runtime.getRuntime();

    Process p = null;

    //dir is the path to where your mongoimport is.

    File dir=new File("C:/Program Files/MongoDB/Server/3.2/bin");

    //this line will open your shell in giving dir, the command for import is exactly same as you use mongoimport in command promote

    p = r.exec("c:/windows/system32/cmd.exe /c mongoimport --db mydb --collection student --type csv --file student.csv --headerline" ,null,dir);

提交回复
热议问题