Tag Archives: MongoDB Error

[Solved] Mongodb Error: NETWORK [thread1] Failed to connect to 127.0.0.1:27017

error:

rico@ubuntu:~$ mongo
MongoDB shell version: 3.2.17
connecting to: test
2017-11-16T23:48:59.362+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2017-11-16T23:48:59.362+0800 E QUERY [thread1] Error: couldn’t connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6

exception: connect failed

Solution:

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 service mongodb start

 

How to Solve MongoDB Error: Authentication failed.

Question:

Implementation db.auth (‘username ‘,’ password ‘),
monodb authentication failed,
error: authentication failed.  appears

environment

Root, admin, and business database user authentication failed

Solution

    1. stop mongodb and open it without authentication,
##Go to the bin directory
cd 
##stop
mongod --shutdown --dbpath=/soft/mongo/mgserver/data/
##start
./mongod --dbpath=/soft/mongo/mgserver/data/ --logpath=/soft/mongo/mgserver/logs/mongod.log --logappend --port=27017 --fork

verify

mongo
show dbs

use  ${your db}
show users

use admin
show users

Modify password
3.1 modify root password:

#
mongo
#
db.changeUserPassword('root','${new  password}')
#
exit

#closed
mongod --shutdown --dbpath=/soft/mongo/mgserver/data/
#Certification Launch
./mongod --dbpath=/soft/mongo/mgserver/data/ --logpath=/soft/mongo/mgserver/logs/mongod.log --auth --logappend --port=27017 --fork

#
mongo
#
use admin
#user, pwd
db.auth('','')

Similarly, change the password of other users

3.2 new users

#
mongo
#
use ${your db}
#
db.createUser({
	user: "",
	pwd:"",
	roles:[{role:"readWrite",db:""}]
})