How to execute a mongo command in sh file? - mongodb

I have a file named db.sh in bin folder and when I try to execute this command $ sh bin/db.sh I receive bin/db.sh: line 2: mongod: command not found in console what is wrong there?
#!/bin/sh
mongod --dbpath db --rest --jsonp;

Here is the situation:
which mongod would give you the path to the mongod binary. If there is no output from which, there which could not find mongod. This may be the case that there is not path in the $PATH variable, that contains the mongod binary. You can make sure by executing echo $PATH.
If you have your MongoDB installed manually, in some directory, then you will need to add /path/to/your/mongodb/bin to the $PATH variable in your .bashrc, like this:
PATH=/path/to/your/mongodb/bin:$PATH
But anyway :) seems like you do not have MongoDB installed on your machine. Follow this article to install it.

Related

Deployd dpd failed to start MongoDB $PATH problem despite having $PATH set; --mongod option also does nothing

so I have this problem where whenever I try to run any variation of dpd command such as "dpd -d" "dpd -d --mongod "C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe" or "dpd -p 5500 app.dpd" I constantly get the error: (I am using Windows 10)
deployd CLI version 2.0.2
starting deployd
Failed to start MongoDB (Make sure 'mongod' are in your $PATH or use dpd --mongod option. Ref: http://docs.deployd.com/docs/basics/cli.html)
Yes, I do have mongod directory in my PATH.
I have checked and my PATH variables for user and global are set to the /bin direction of mongod.
I have tried running it while mongod.exe is running and when it's closed, setting the PATH by the %PATH% command etc. I have ran out of options at this point. I did manage to run the dashboard once but there was 404 [Object object] only written there and then I couldn't reopen it again. Any ideas? None of the solutions from SO worked for me so far.

mac: command not found: mongod

I installed mongodb by brew on my MacOS as the mongodb official documentation, but I tried to run MongoDB manually as a background process, use command "mongod --config /usr/local/etc/mongod.conf --fork". Then the terminal displayed the message is : command not found: mongo.
Did I miss any steps?
The above error appears when mongodb executable is not included in the PATH environment variable.
MongoDB gets installed to /usr/local/bin/mongod
The command 'mongod --config /usr/local....' will work only if '/usr/local/bin' is included in PATH.
How to fix the problem?
The problem can be fixed in 2 ways -
Calling the mongod command with full path
/usr/local/bin/mongod --config /usr/local/etc/mongod.conf --fork
Adding '/usr/local/bin' to PATH
export PATH=$PATH:/usr/local/bin
Run the above command or add the above line to the end of .zshrc file and .bash_profile file and execute mongodb command in a new terminal window.
mongod --config /usr/local/etc/mongod.conf --fork

Find out what happened to my data in mongodb?

I'm using mongodb in a project. I shut down mongodb and when I restarted mongodb all my databases and collections were gone. How do I figure out what happened?
In order to find the files, you can check the db path. You can do this by using
grep dbPath /etc/mongod.conf
(on default installations). This should return a line with the path to the files.
If the first command does not work, you can use the command
ps aux | grep mongo
and search for the mongod process. There should be something like this on the output:
/usr/bin/mongod --config /etc/mongod.conf
If there is a --dbpath argument on the process, you should look there for the files.
And in case your files are not in the dbpath fodler, the last resource I can think of is searching for the files on the whole file system:
sudo find / -name 'mongo*'
(you should find the mongod.lock file in the folders that were already used by Mongo).
If you happen to find your files in another folder that is not being used by Mongo, then you'll have to change the dbPath on config.

Can not run mongo command in terminal

I installed mongoDB with a .tar in a certian directory and I can only run mongo in that directory if i use
./mongo
Otherwise if i try to just use
mongo
The terminal will tell me that it is not installed. What should I do?
Try, adding the following line to the .bashrc
alias mongod='path_to_mongodb/bin/mongod'
alias mongo='path_to_mongodb/bin/mongo'

Settup up mongodb

I was following this quickstart guide, http://www.mongodb.org/display/DOCS/Quickstart+OS+X, but I got lost when they told me to to execute ./mongodb-xxxxxxx/bin/mongod, in which directory do I execute this command? I tried to find / -name mongodb results matched that directory format.
To start Mongo, run that command in the root installation directory of mongo, so, assuming you installed mongo in /opt/mongo/mongodb-linux-x86_64-2.0.2, just run in that folder like this...
/opt/mongo/mongodb-linux-x86_64-2.0.2$ ./bin/mongod
Add any additional parameters you need to start the instance, this is how I run my instance....
./bin/mongod --fork --dbpath /opt/mongo/data/db1/dbs --port 33479 --logpath /opt/mongo/data/db1/log/db1.log -logappend
My personal favorite way to install just about anything, including MongoDB, on Mac OS X:
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
brew install mongodb