Mongo Import csv file

I am working mongo import using Java application. My requirement is very large file around 500MB csv file .these needs to be import into DB. I am not find much resource related like mongo client or mongo driver.
following like of code I am using but not working
val r = Runtime.getRuntime()
var p: Process? = null
val command = “C:\Program Files\MongoDB\Server\4.2\bin\mongoimport.exe --uri mongodb://admin:secret@ --collection my_collection --drop --type csv --headerline”+filePath
try {
p = r.exec(command)
//var buf: BufferedReader= BufferedReader(InputStreamReader(p.inputStream))
//var line=“”
//while ((line==buf.readLine())!= null && buf.readLine()!=“”)
// println(line)
println(“Reading csv into Database”)
Please guide us

Hi @Basayya_Kulkarni,

Welcome to the MongoDB Community.

Can you share the error you are seeing when you run this program?

What happens when you run the mongoimport command standalone from the command line?


val process = Runtime.getRuntime().exec(command)

        val waitFor: Int = process.waitFor()

process.waitFor() -This waitfor is not returning and it hangs

@ Joe_Drumgoole
Thank you so much for your help

When I run the same command in command standalone from the command line and it works fine. when use the same command in JAVA .process.waitFor() it hangs for large data set(Excel)