10
votes

I'm trying to setup a cronjob for a regularly scheduled import of json data into a mongo database. To conduct the import, I have the following command in the Python script that the cronjob runs:

os.system("mongoimport --jsonArray --db %s --collection %s --file .../data.txt" %(db_name,collection_name))

However, the log file of the cronjob keeps displaying the following error:

sh: mongoimport: command not found

I think I need to call mongoimport with the full file path in the code, but I'm not sure where mongodb/mongod/mongoimport is installed on my system. whereis mongoimport, whereis mongodb, whereis mongod all return nothing.

I installed mongodb with Homebrew. Packages installed with Homebrew are located in /Library/Caches/Homebrew. However, in my system that folder only has a mongodb-2.6.4_1 tar file. Do I have to unpack this tar file to access mongoimport?

Thanks for your help.

6
does mongo command works?Ravi

6 Answers

45
votes

As of June 2020, I installed mongodb latest version using brew as per the documentation , and I faced the same issue command not found: mongoimport .

I had to to install mongodb-database-tools

brew install mongodb/brew/mongodb-database-tools

Then I could use mongoimport

Just adding this solution, incase it helps someone

9
votes

Got the same issue, but I installed mongodb via Mac Port. Unfortunately, from version 3 of mongodb, these mongodb tools are maintained as a separate project, so I updated Mac port to latest version then installed mongo tools separately.

sudo port install mongo-tools

Hope this helps someone that installing mongodb by mac port.

6
votes

If you installed MongoDB correctly you need to create a ~/.bash_profile and assign /usr/local/mongodb/bin to the $PATH environment variable

After that you should be able to access the mongoimport command

0
votes

If you used brew for installation, mongod is in /usr/local/bin/ directory. Other utilities (mongoimport, mongoexport etc.) are in the same path. All you need to do is open another terminal.

0
votes

Visit https://www.mongodb.com/download-center/community and you can download a tarball for MacOS, which contains all the tools including mongoimport.

Untar, add to you PATH and voilà!

-2
votes

Try using ./mongoimport or sudo ./mongoimport

After following all of these examples, I was able to use it that way from bash.