mongoDB error: Error: failed to connect to [localhost:27017] - mongodb

I'm trying to install habitrpg locally but I keep getting a mongoDB error after typing node src/seed.js:
Error: failed to connect to [localhost:27017]
I saw on other questions with the same error people have suggested typing in 'mongod' and that fixes it by creating a local server. I get the error:
-bash: mongod: command not found
Can't figure out what's wrong. Any ideas?

Open CMD (In Windows) or terminal (In Ubuntu).
type command >cd PATH_FOR_MONGODB_BIN_FOLDER
cd C:\Program Files\MongoDB\Server\3.2\bin
for ubuntu command will be same :
cd /home/MongoDB/Server/3.2/bin
then type command >mongod --dbpath PATH_FOR_DATA_FOLDER
mongod --dbpath C:\data\db
For ubuntu command will be :
./mongod --dbpath /home/data/db
you can specify any folder as data folder.
Wait till CMD or Terminal shows "waiting for connections"
2016-09-01T21:38:33.170+0530 I NETWORK [initandlisten] waiting for connections on port 27017
Then open new CMD or terminal window.
type command >cd PATH_FOR_MONGODB_BIN_FOLDER ( same as step 3 )
cd C:\Program Files\MongoDB\Server\3.2\bin
Don't close previous window of cmd or teminal.
then run mongodb by typing "mongo" in windows or "./mongo" in ubuntu
mongo
For ubuntu
./mongo
After mongodb run successfully you can close previous CMD window.

You don't have MongoDB installed. Follow the directions for your system to install it: http://docs.mongodb.org/manual/installation/
From the habitRPG docs:
Before starting make sure to have MongoDB, NodeJS and npm and Git installed and set up.

I think that you don't have an environmental variable declared. Assuming that your MongoDB installation is C:\ProgramFiles\MongoDB\Server\YOUR_VERSION_NUMBER\, you should just add the bin folder path of that version of MongoDB to your PATH system environment variable.
Here's a link where you can find the way to do that without complications :
http://www.computerhope.com/issues/ch000549.htm

After installing MongoDb you have to add the directory "data\db" under the C:\ directory,
then you should start the mongod.exe

on windows open task manager || Ctrl + shift + ESC > select service tab > search for mongo db > right click > start service

I got this issue because I didn't have MongoDB. So I installed MongoDB and tried to run node application and it worked.
If you don't have MongoDB then follow below steps to install and enjoy
Commands :
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
$ echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
$ sudo apt-get update
$ sudo apt-get install -y mongodb-org
Then type mongo in terminal and if you will get console for mongo then it's done.

Type sudo pip3 install mongodb, then sudo pip3 install pymongo, then mongod.

I had the same problem on my Mac.
I updated my Homebrew files, after I reinstaled MongoDB in my terminal
brew tap mongodb/brew
and
brew install mongodb-community#5.
and I started mongo server
brew services start mongodb/brew/mongodb-community
After that I coud to commect.

my problem is the connectoon is down, run script:
brew services start mongodb-community
And up mongoDB Compass and works.

I ran mongodb install file and choose repair

Related

MongoDB , zsh: command not found: mongo

I just installed MongoDB through homebrew and ran it as a macOS service, then I started the server with command:
brew services start mongodb-community#4.4
==> Successfully started mongodb-community#4.4 (label: homebrew.mxcl.mongodb-community#4.4)
so it's running
but when I tried to run the mongo shell with command: mongo
it just showed zsh: command not found: mongo
add the mongo location path to the zsh PATH variable:
echo export PATH=/opt/homebrew/opt/mongodb-community#4.4/bin:$PATH >> ~/.zshrc
open new terminal and try starting again

zsh: command not found: mongo

I'm following the official instructions found here (on Mac OS Big Sur): https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/
When attempting to run mongo, I receive:
zsh: command not found: mongo
I then check if MongoDB is running by running:
brew services start mongodb-community#4.4
I then receive:
Service mongodb-community#4.4 already started, use brew services restart mongodb-community#4.4 to restart
Because of this, I know MongoDB is running. What gives? I followed the official instructions from MongoDB's website.
For Apple M1 Processor:
If you install mongodb through Homebrew, follow the steps below:
Open up your Terminal
Type brew list to check the formulae of the installed mongodb
==> Formulae
mongodb-community#4.4 mongodb-dxxx...
==> Casks
xxxxx
In my case, it is mongodb-community#4.4.
In the terminal, type brew list mongodb-community#4.4 to get the directory of the mongodb installed in your machine.
/opt/homebrew/Cellar/mongodb-community#4.4/4.4.13/bin/install_compass
/opt/homebrew/Cellar/mongodb-community#4.4/4.4.13/bin/mongo
/opt/homebrew/Cellar/mongodb-community#4.4/4.4.13/bin/mongod
/opt/homebrew/Cellar/mongodb-community#4.4/4.4.13/bin/mongos
/opt/homebrew/Cellar/mongodb-community#4.4/4.4.13/homebrew.mxcl.mongodb-community#4.4.plist
/opt/homebrew/Cellar/mongodb-community#4.4/4.4.13/MPL-2
/opt/homebrew/Cellar/mongodb-community#4.4/4.4.13/THIRD-PARTY-NOTICES
Copy the bin path of your mongodb: /opt/homebrew/Cellar/mongodb-community#4.4/4.4.13/bin
Open up your .zshrc file with any text-editor
Add this line to the file:
export PATH="/opt/homebrew/Cellar/mongodb-community#4.4/4.4.13/bin:${PATH}"
Try mongo --version in your terminal, if you see similar output like shown below, you are good to go.
MongoDB shell version v4.4.13
Build Info: {
"version": "4.4.13",
"gitVersion": "df25-----------b9246",
"modules": [],
"allocator": "system",
"environment": {
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
I did the above procedures and it still didn't work. But use this, then it worked!
brew install mongodb-community-shell
I solved my problem with this command running on terminal but only path I added is diffrent
Steps:
brew list mongodb-community#4.0. (run this first)
then copied /opt/homebrew/Cellar/mongodb-community#4.0/4.0.28/bin. this path
and executed:
echo 'export PATH="/opt/homebrew/Cellar/mongodb-community#4.0/4.0.28/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Then I have checked by openning .zshrc file is my path has set on not by executing - nano .zshrc command
echo 'export PATH="/usr/local/opt/mongodb-community#4.4/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
I did the above procedures and it still didn't work. But I restarted my terminal using $exec bash -l and it works!

mongodb installation on mac using brew with zsh

I'm using zsh and installed mongo using: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/
when trying to use mongod --config /usr/local/etc/mongod.conf --fork I get:
➜ ~ brew list
gettext openjdk scala#2.11
git pcre2
mongodb-community#4.0 sbt
➜ ~ brew services start mongodb-community#4.0
Service `mongodb-community#4.0` already started, use `brew services restart mongodb-community#4.0` to restart.
➜ ~ mongod --config /usr/local/etc/mongod.conf --fork
zsh: command not found: mongod
Can someone help?
It looks like you haven't set path variable for mongodb. You can set it in .zshrc file.
Open .zshrc file in vim using vim ~/.zshrc
then paste the following line
export PATH="<your mongodb bin folder path>:$PATH"
in my case the path is
/Users/namardeepsood/Development/mongodb/bin
save this file and run source ~/.zshrc to refresh the current shell environment.

How to fix ''mongod: command not found " error in AWS Cloud9

I want to install MongoDB in my AWS Cloud9 server. So I followed the instruction as the Cloud9 community page says, but the command to run the MongoDB server in c9 command line i.e.,
$ *./mongod* returns ./mongod: line 1: mongod: command not found.
help me to fix this.
I've tried searching about it on YouTube but it didn't work.
$ *sudo yum install -y mongodb-org*
Loaded plugins: priorities, update-motd, upgrade-helper
1062 packages excluded due to repository priority protections
No package mongodb-org available.
Error: Nothing to do
$ mkdir data
$ echo 'mongod --bind_ip=$IP --dbpath=data --nojournal --rest "$#"' > mongod
$ chmod a+x mongod
$ ./mongod
./mongod: line 1: mongod: command not found
We can start mongodb by running the mongod script on your project root:
command :- ./mongod
From the error given below, it is apparent that the mongo repo wasn't configured in your yum package manager.
vocstartsoft:~ $ sudo yum install -y mongodb-org
Loaded plugins: priorities, update-motd, upgrade-helper 1062 packages excluded due to repository priority protections No package mongodb-org available. Error: Nothing to do
Create /etc/yum.repos.d/mongodb-org-4.0.repo and write the following in it.
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
Or add the repo directly from the .repo file,
yum-config-manager --add-repo https://repo.mongodb.org/yum/amazon/mongodb-org.repo
Then run,
sudo yum install -y mongodb-org
Reference
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/
Either try this: sudo apt install mongodb-clients
Or consider the below process:
ubuntu:~/environment $ At the terminal you’ll see this.
Enter touch mongodb-org-3.6.repo into the terminal
Now open the mongodb-org-3.6.repo file in your code editor (select it from the left-hand file menu) and paste the following into it then save the file:
[mongodb-org-3.6]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc
* Now run the following in your terminal:
sudo mv mongodb-org-3.6.repo /etc/yum.repos.d
sudo yum install -y mongodb-org
If the second code does not work try:
sudo apt install mongodb-clients
Close the mongodb-org-3.6.repo file and press Close tab when prompted
Change directories back into root ~ by entering cd into the terminal then enter the following commands:
“ubuntu:~ $ “ - Terminal should look like this.
sudo mkdir -p /data/db
echo 'mongod --dbpath=data --nojournal' > mongod
chmod a+x mongod
Now test mongod with ./mongod
Remember, you must first enter cd to change directories into root ~ before running ./mongod
Don't forget to shut down ./mongod with ctrl + c each time you're done working
-if this error pops up while using command mongod
exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, terminating
Then use the code:
sudo chmod -R go+w /data/db
Reference

Mongo DB installation issue

I installed mongo DB by using docs of mongo DB. But when I tried this command in ubuntu terminal, I got this error:
Command used:
sudo mongod
Error:
*********************************************************************
ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
How can I fix this error?
Run this command to create a directory -
sudo mkdir /data/db
and then run
sudo mongod
If you installed mongo as a service (for example, using the following docs: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/), simply execute:
sudo service mongod start
Otherwise, if you simply wish to try mongo without any specific configuration, you can supply a directory for the db files by executing:
mongod --dbpath /path/to/db &
Simple Mongo Setup on AWS Unbuntu 14.0 - By Hrushikesh Kulkarni
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update sudo apt-get install -y mongodb-org sudo apt-get install php5 sudo apt-get install apache2 sudo apt-get install libsasl2-dev sudo apt-get install php-pear php5-dev sudo pecl install mongo
Add Below Stuff in /etc/php5/apache2/php.ini
extension_dir = "/usr/lib/php5/20121212" extension=mongo.so sudo service apache2 restart
Create php File in /var/www/html Run file in browser and find Extension "Mongo"
If you have created Test123 folder then
Run following command to restart the mongodb service
sudo service mongodb restart
Then change the db for the mongodb
Use following command
sudo mongod --dbpath Test123
Here Test123 is directory that you have created on specific location.