Use Same Connection for Multiple mongoimport Calls

I have many .csv files I’m bringing into MongoDB using the mongoimport command. Each time I call the command, it opens a new connection to my cluster.

Is there a way I can use this command more than once and maintain the same connection?

From engineering perspective i don’t think you can do both at the same time. mongoimport is a command line tool and each run will create a separate process. They are independent and are not able to share connections.

But you can check if options support importing multiple files in a single run.


If your .csv files are moderately big the overhead of opening a connection per file should not be significant for the overall process.

If Kobe_W suggestion does not work and doing everything in a single connection is critical you may always write your own importer and uses bulkWrite to import multiple .csv using the same connection.