Can not run mongo command in terminal - mongodb

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'

Related

Cannot mongodump to a single archive

I'm trying to dump a MongoDB database to an archive. Using the following command as given in documentation.
sudo mongodump --uri=mongodb://username:password#host:27017/dbname?authMechanism=SCRAM-SHA-1&authSource=authdb --archive=file.archive
But it doesn't dump as expected rather it creates a dump folder with .json file for each collection, which should be a single archive file as given.
It also shows the following error -
--archive=file.archive: command not found
Mongo version -
MongoDB shell version v3.6.3
I had this problem & I figured out the reason it was happening.
The command I was running was
sudo /usr/bin/mongodump --uri=mongodb+srv://{username}:{password}#{atlasendpoint}.mongodb.net/?retryWrites=true&w=majority --archive={filename}.archive --gzip 2>&1
I was getting the same error as you. I change the shell command by wrapping quotation marks around the URL; this fixed it for me.
sudo /usr/bin/mongodump --uri="mongodb+srv://{username}:{password}#{atlasendpoint}.mongodb.net/?retryWrites=true&w=majority" --archive={filename}.archive --gzip 2>&1

brew services start postgresql not working

I have installed postgres in Mac using command
brew install postgresql#9.6
and is successfully installed
brew services start postgresql#9.6 is successful also
==> Successfully started postgresql#9.6 (label: homebrew.mxcl.postgresql#9.6)
But when I tried to access Postgres from my Mac terminal psql postgresql#9.6 it prompt me weird error
-bash: /usr/local/bin/psql: No such file or directory
Am I doing something wrong, how to open psql from my terminal
Why there is no psql file in my /usr/local/bin
The accepted answer is incorrect.
If you install postgresql#9.6 via Homebrew, the right path for the /bin folder is:
/usr/local/Cellar/postgresql#9.6/9.6.15/bin
To connect, just type: psql postgres
If you're curious about the connections details, just type \conninfo and check it.
You must to enabling Postgres command line tools.
If you are using the default terminal, you are going to want to modify the file at
~/.bash_profile
. If you are using something like Oh My Zsh you are going to want to modify the file ~/.zshrc.
To edit this file you likely need to open it via the terminal, so open your terminal and type open ~/.bash_profile. You can replace the word open with subl or whatever text editor you prefer.
Once your zbash_profile or .zshrc file is open, add the following line to the end of the file:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
After that you will need to quit and restart your terminal This is to make sure it reloads with the changes you just made.
Once you have restarted your terminal, try running psql.
psql -U postgres
You should get the following output.
psql (9.6.0)
Type "help" for help.
postgres=#
You can read more on https://www.calhoun.io/how-to-install-postgresql-9-6-on-mac-os-x/

Running PostgreSQL commands from anywhere on the terminal

First off, let me say that I'm new to both using Mac and PostgreSQL. I just installed Postgres using their installer and it was installed in /Library/Postgres/... when I tried running createdb from the terminal it returned an error createdb: command not found. I ended up using /library/postgresql/9.6/bin/createdb before I coud get it to work.
Here's my question, how do I set it so that I don't have to type in the full path again to use the createdb command.
I'd love a detailed explanation.
Thanks
First you need to execute the psql command to get into the postgresql interacive shell.
In your terminal:
psql
Postgresql interactive shell should start. In this shell
> createdb yourdatabasename;
Btw: If psql is not found you will probably need to add it to your path and restart your terminal, something like this with the path matching your machine:
export PATH=/Library/PostgreSQL/9.5/bin:$PATH

How to execute a mongo command in sh file?

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.

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