i have following step.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
sudo gedit /etc/apt/sources.list
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
sudo apt-get install mongodb-10gen
when i run command
mongo --version
result was
MongoDB shell version: 2.4.9
then at command
sudo start mongodb
result
mongodb start/running, process 5808
at command
sudo stop mongodb
result was
stop: Unknown instance:
at command
mongo
result was .MongoDB shell version: 2.4.9
connecting to: test
Sun Mar 2 18:57:50.050 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
again on command
sudo service mongodb restart
stop: Unknown instance:
mongodb start/running, process 5873
mongo
MongoDB shell version: 2.4.9
connecting to: test
Sun Mar 2 18:57:50.050 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
Did you try to remove .lock file from /var/lib/mongodb/ ?
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongodb restart
Also you can try: sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/ and then start mongo again.
Hope this helps
Related
I am using aws and installed ubuntu server on aws ec2.
I installed mongodb on it.
When installing mongodb, it is working well.
But If i reboot server and try to connect mongod in termina. I am getting the following error.
MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:362:17
#(connect):2:6
exception: connect failed
exiting with code 1
So whenever reboot server, i have to execute the following command and then mongo is working again.
sudo systemctl stop mongod
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair --dbpath /var/lib/mongodb
sudo mongod --fork --logpath /var/lib/mongodb/mongodb.log --dbpath /var/lib/mongodb
sudo systemctl start mongod
I think whenever reboot server, executing above command does not make sense.
If anyone have experienced, please help me.
Thanks.
After you setup the mongodb you usually would enable it, so that it starts after each reboot:
sudo systemctl enable mongod
I'm trying to connect to a localhost database with mongodb-community 4.2.2, but I'm having connection refused:
MongoDB shell version v4.2.2
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-01-17T14:49:50.057+0100 E QUERY [js] Error: couldn't connect to server
127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to
127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:341:17
#(connect):2:6
2020-01-17T14:49:50.060+0100 F - [main] exception: connect failed
2020-01-17T14:49:50.060+0100 E - [main] exiting with code 1
I don't know what is going on. I tried:
brew uninstall --force mongodb-community
rm -rf /homebrew.mxcl.mongodb-community.plist
rm -rf /Cellar/mongodb-community/ folder
brew update
brew install mongodb-community
And all kind of approaches, but nothing solved my problem...
Anyone can help?
If you install mongodb through brew, try running this command to start it:
mongod --dbpath /usr/local/var/mongodb
Try following these instructions: LINK
Then manually delete the content within /usr/local/var/mongodb.
Finally, restart the mongodb-community service.
Regards
To reconnect DB, just run the command that #user129916 suggested.
sudo mongod --dbpath /usr/local/var/mongodb
If the error is "Failed to unlink socket file /tmp/mongodb-27017.sock Permission denied":
Delete the file:
/tmp/mongodb-27017.sock
Set the mongoDB configuration file:
mongod -f /usr/local/etc/mongod.conf
Set path to DB
sudo mongod --dbpath /usr/local/var/mongodb
For me the issue was caused by a combination of IPV6 and /tmp/mongodb-27017.sock permission after the update. I fixed it by completely removing mongo and the .sock reinstalling and also adding ipv6 to the config.
Steps below:
Completely remove mongodb-community
sudo rm -rf /usr/local/Cellar/mongodb-community
brew cleanup
Recreate mongodb directory
sudo rm -rf /usr/local/var/mongodb
cd /usr/local/var && mkdir mongodb
Remove /tmp/mongodb-27017.sock
cd /tmp
sudo rm -rf mongodb-27017.sock
Reinstall mongodb-community
brew install mongodb-community
brew services start mongodb-community
brew services list
Possibly optional. Needed to call restart since it had a permission error wanting sudo but it didn't like that and restart seemed to work without sudo
brew services restart mongodb-community
If your error says something like ... ECONNREFUSED ::1:27017 also add the following steps
Update mongod.conf to also accept IPV6
vi /usr/local/etc/mongod.conf or your preferred editor
Add
ipv6: true
bindIp: ::1, 127.0.0.1
I'm trying to install mongoDB on Ubuntu Server 14.04 with apt-get.
My command ist sudo apt-get install mongodb-org -y
After installation I'm trying to run sudo service mongod start
The output is mongod start/running, process 11977
Trying to get status sudo service mongod status prints out mongod stop/waiting
Trying to stop mongod sudo service mongod stop prints stop: Unknown instance:
When I type mongo in command line I get this
MongoDB shell version: 2.6.3
connecting to: test
2014-08-02T11:49:28.781+0200 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-08-02T11:49:28.782+0200 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
What I'm doing wrong?
mongod is not running, thats why you cant connect. Before you run it as a service, just run mongod from the command line and see how it fails. Once you get it working, you can convert to a service.
I first execute the command:
sudo service mongodb restart
I get the prompt:
stop: Unknown instance:
mongodb start/running, process 3175
Then,I execute the command:
mongo
I get the error:
MongoDB shell version: 2.4.6
connecting to: test
Tue Oct 8 19:48:08.961 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
I don't know how I get this error.
Execute the following command
sudo rm -rf /var/lib/mongodb/mongod.lock
then
sudo service mongodb restart
Just Execute these following lines:
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo start mongodb
sudo status mongodb
mongo
Now you can access to your mongo terminal.
I installed MongoDB on ubuntu 11.04 followed by this site. I gave this command to run MongoDB
sudo /etc/init.d/mongodb start
It showed some error like this
sudo: /etc/init.d/mongodb: command not found
I checked the file.But it was okay.Can any one tell me how to solve this.
Please help me .I am newbie to mongoDB.
[edited] When I am connecting to mongo it is showing error like
connecting to: test
Sun Jul 3 09:57:29 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:79
You may should try to run:
mongo --nodb
This worked for me.
Regarding to the connection error, you can try:
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
This starts the daemon using the config file /etc/mongodb.conf and repair the database.
Then start the database:
sudo -u mongodb mongod -f /etc/mongodb.conf