I'm trying to launch mongo through my script after installing mongodb, but it throw an error but when I try "mongo" from my terminal it works perfectly.
Error when I run mongo from my script :
MongoDB shell version: 3.2.21
connecting to: test
2018-10-11T10:38:32.855+0200 W NETWORK [thread1] Failed to connect to
127.0.0.1:27017, in(checking socket for error after poll), reason:
errno:111 Connection refused
2018-10-11T10:38:32.877+0200 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
Here is a part of my script
apt-get install -y mongodb-org
systemctl enable mongod
systemctl start mongod
echo " " >> /etc/mongod.conf
echo "replication:" >> /etc/mongod.conf
echo " oplogSizeMB: 1" >> /etc/mongod.conf
echo " replSetName: rs0" >> /etc/mongod.conf
sed '24d' /etc/mongod.conf
systemctl restart mongod
export LC_ALL=C
mongo --eval "rs.initiate()"
But when i just run "mongo" command on my terminal it works :
# mongo
MongoDB shell version: 3.2.21
connecting to: test
rs0:OTHER>
what might be the problem, please?
try with the following line:
/bin/bash -c "mongo --eval \"rs.initiate()\""
Related
I have recently installed Wekan on a CentOS (CentOS Linux release 7.6.1810) server and it works well. However I need to login to the MongoDB. I have followed the installation guide of MongoDB and set a password for 'admin' user. But when When the "mongo -u admin -p" command is entered it prompts for password and I get the following error. However I have another issue not starting "mongod", but it is enabled.
connecting to: test
2020-06-12T01:20:23.618-0400 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2020-06-12T01:20:23.618-0400 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
I created this user in mongo which does not seem to work when trying to login to the DB.
$ mongo
db.createUser(
{
user: "admin",
pwd: "abcd1234",
roles: [ { role: "root", db: "admin" } ]
}
)
Firstly I installed the latest version of mongodb and then I downgraded to to 3.2 which works with wekan. However Wekan still works fine without any issue.
This is the error I get when starting the mongod.
$ systemctl start mongod
Job for mongod.service failed because the control process exited with error code.
See "systemctl status mongod.service" and "journalctl -xe" for details.
$ systemctl enable mongod
mongod.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mongod on
The port mongod uses is 27019 which I found from the following command.
$ ss -nutlp
tcp LISTEN 0 128 127.0.0.1:27019 *:* users:(("mongod",pid=11578,fd=6))
What am I doing wrong here?
In the output of the mongo shell connection failure:
Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
This tells you that it is attempting to connect to port 27017 on localhost, and that the operating system actively refused the connection because nothing is listening on that port.
The ss output shows that mongod is listening on port 27019.
Try adding --port 27019 to your mongo command line.
I have installed Mongo on my OSX
$ brew info mongodb
mongodb: stable 4.0.2 (bottled)
...
I'm starting MongoDB service by this command:
$ brew services start mongodb
I can observe the status of mongodb:
$ brew services list
Name Status User Plist
mongodb started megas /Users/megas/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
...
But when I'm running mongo client it give me an error:
$ mongo
MongoDB shell version v4.0.2
connecting to: mongodb://127.0.0.1:27017
2018-09-19T15:18:22.490+0300 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:257:13
#(connect):1:6
exception: connect failed
When I manually start mongod then it works as it should be.
What I'm missing here?
Update:
If I run it manually it throughs message and stops
$ mongod --config /usr/local/etc/mongod.conf
2018-09-19T21:47:51.531+0300 I CONTROL [main] Automatically disabling
TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
$ cat /usr/local/etc/mongod.conf
# Store data in /usr/local/var/mongodb instead of the default /data/db
dbpath = /usr/local/var/mongodb
# Append logs to /usr/local/var/log/mongodb/mongo.log
logpath = /usr/local/var/log/mongodb/mongo.log
logappend = true
# Only accept local connections
bind_ip = 127.0.0.1
I am trying to connect and run mongodb in docker. But it is showing error.
$docker pull mongo $ docker run -it mongo sh -c 'exec mongo
"$MONGO_PORT_27017_TCP_ADD R:$MONGO_PORT_27017_TCP_PORT/PMSDB" '
MongoDB shell version v3.6.2 connecting to: mongodb://:/PMSDB
2018-01-30T10:31:34.696+0000 E QUERY [thread1] Error: Empty host
component parsing HostAndPort from ":" :
connect#src/mongo/shell/mongo.js:251:13 #(connect):1:6 exception:
connect failed
user2#system2 MINGW64 ~/sample $
How to resolve this
I have followed this steps and install MongoDB in my Linux mint and finally run this command
mongo --host 127.0.0.1:27017
But got this error after run this command.
MongoDB shell version: 3.2.18
connecting to: 127.0.0.1:27017/test
2017-12-21T13:16:20.693+0530 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-12-21T13:16:20.693+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:231:14
#(connect):1:6
exception: connect failed
I have already run this command also
sudo service mongod start
But after this command,
mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset:
Active: failed (Result: exit-code) since Thu 2017-12-21 13:35:28 IST; 6s ago
Docs: https://docs.mongodb.org/manual
Process: 4891 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (cod
Main PID: 4891 (code=exited, status=100)
I found many solution but did not get it resolved. Thanks in advance.
Make sure mongod service is running locally
sudo service mongod status
and if it's not, run sudo service mongod start
If that doesn't help, try this:
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair
and run service mongod start again
EDIT
Try changing permissions in the mongodb folder
cd /var/lib/mongodb
sudo chown -R mongodb:mongodb *
Also, If that doesn't help, run this
sudo /usr/bin/mongod --config /etc/mongodb.conf
and tell me the output (If it works is doesn't solve your problem, the service startup still needs to be fixed, just curious)
i installed mongodb in ubuntu usinfg the following links
https://askubuntu.com/questions/724749/install-mongo-3-2-on-ubuntu-15-10
root#karthickeyan:/home/karthickeyan# mongo
MongoDB shell version: 3.2.9
connecting to: test
2016-08-20T01:17:08.198+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-08-20T01:17:08.198+0530 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
Create the file /lib/systemd/system/mongod.service with the following content:
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf
[Install]
WantedBy=multi-user.target
Start the service:
sudo service mongodb start
Then run the command:
mongo
You will then access the server. Hope it works for you. :)