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.
The databases are stored in the /usr/local/var/mongodb/ directory. The mongod. conf file is here: /usr/local/etc/mongod.
mongoimport is located in the bin directory (eg, /mongodb/bin or wherever you installed it). To import data, open a new Terminal/Command Prompt window and enter mongoimport followed by parameters such as database name, collection name, source file name, etc.
“how to check if mongodb is installed” Code Answer'sOpen the command prompt and type "cd c:\program files\mongodb\server\your version\bin". After you enter the bin folder type "mongo start". If you get either a successful connection or failed one it means it's installed at least.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With