Is there any way to run mongo scripts without having mongo shell installed?

Currently , I have an java mongo connector app that connects to mongo database and inserts a json file content into database. I am planning to achieve the same using mongoimport command as part of a script .I would like to check is there any way that we can run mongo scripts without having mongo shell installed on the machine?

mongoimport does not need mongo shell installed to do its work

Welcome to the MongoDB Community Forums @Ravi_Teja_Muddada1 !

Can you provide more context on your requirements for a script? If you are already importing JSON via Java you can avoid external tool dependencies like mongo or mongoimport. Conversely, if you have straightforward import needs you can use mongoimport which will be simpler to install than a Java application.

For some examples of how to import JSON, see: JSON to MongoDB.

Regards,
Stennie

Hi @Stennie ,
Thanks for the reply !
Its a straight forward import of a JSON file into mongo. This is the reason I don’t want to run a java app to to do that
I am aware that we can do it in single line command using mongoimport . I would like to know , if I write a mongoimport script and run it a remote VM , does that VM need to have mongodb / shell installed to identify the command mongoimport?

Hi Steev , Thanks for the reply!
so you mean to say , mongoimport command can be run without having any additional installation of mongodb / shell on the machine and the command can be recognized just like default linux commands like cat / ls?

Hi @Ravi_Teja_Muddada1 ,

mongoimport is a standalone binary: it does not rely on the mongo shell or a local mongod.

Regards,
Stennie

Hi @Stennie
If I don’t have mongodb installed or not having it on Path after installation - mongoimport command is failing with the below error message
" mongoimport is not recognized as an internal or external command"

mongoimport is part of the database tools package (which includes mongoimport, mongoexport, mongodump and mongorestore). You can find packages for all the operating systems here: https://www.mongodb.com/try/download/database-tools.

2 Likes

Hi @Ravi_Teja_Muddada1,

The mongoimport binary must be discoverable via your $PATH environment variable or you have to specify the path to mongoimport when invoking the command.

As @Massimiliano_Marcon mentioned, mongoimport and related database tools (mongoexport, mongodump, mongorestore, …) can be installed via the Database Tools package or tarball.

If you only want to have the mongoimport tool available, you can copy the binary from the tarball (tgz) install of the database tools for your O/S version.

Regards,
Stennie

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.