Mongo Shell only connects with prepended host - mongodb

I have a new mongodb setup.
my running mongo process is this:
mtp 26776 0.0 0.0 4104 464 ? S Apr14 0:41 /command/svscan /home/mtp/service
mtp 26779 0.0 0.0 3932 392 ? S Apr14 0:01 \_ supervise mongodb
mtp 14413 0.5 0.2 337744 53660 ? Sl 14:57 0:04 | \_ mongod --dbpath /home/mtp/mongodb --bind_ip 127.0.0.1 --port 21111 --auth --nohttpinterface --smallfiles
I connect to it by main admin:
mongo admin --port 21111 -u mtp_mongoadmin -p
I create a db
$use errbit-production
> switched to db errbit-production
I create a user on that db which can read and write:
db.createUser({user: "mtp-production", pwd: "blah", roles:["readWrite"]})
But I cannot connect
$ mongo --port 2111 --host localhost -u mtp-production -p
MongoDB shell version: 2.6.12
Enter password:
connecting to: localhost:2111/test
2016-04-18T15:14:44.607+0200 warning: Failed to connect to 127.0.0.1:2111, reason: errno:111 Connection refused
2016-04-18T15:14:44.608+0200 Error: couldn't connect to server localhost:2111 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:148
exception: connect failed
The only way I can connect is by this
$ mongo localhost:2111/errbit-production -u mtp-production -p
MongoDB shell version: 2.6.12
Enter password:
connecting to: localhost:2111/errbit-production
>
Why is this? And how can I solve this?

Related

couldn't run mongo through a script

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()\""

MongoDB Docker container refuses connection when auth enabled

If I set up my container without auth eg)
docker run --name some-mongo -d -p 27017:27017 mongo
I can connect to my mongoDB from a remote machine eg)
mongo [serverIP]
However, my issue is when using the --auth flag
Following the documentation:
docker run --name some-mongo -d -p 27017:27017 mongo --auth
> db.createUser({ user: 'foo', pwd: 'bar', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] })
results in connections being refused:
$ mongo -u foo -p bar [serverIP]
MongoDB shell version v3.4.9
connecting to: [serverIP]
2017-12-09T14:01:41.114-0600 W NETWORK [thread1] Failed to connect to [serverIP]:27017, in(checking socket for error after poll), reason: Connection refused
2017-12-09T14:01:41.115-0600 E QUERY [thread1] Error: couldn't connect to server [serverIP]:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:237:13
#(connect):1:6
exception: connect failed
I double-checked and the port looks to be open on the server:
$ netstat -tuplen
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
...
tcp6 0 0 :::27017 :::* LISTEN 0 53238875 -
...
(Docker is running on a debian Digital Ocean droplet)
You need to specify the --authenticationDatabase flag
mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"
see the tutorial

Unable to start MongoDB shell for mongos daemon

I am trying to setup a sharded mongodb cluster using 4 solaris-11 servers which are on the same rack. The following sharded config is being attempted:
Server A : Replica set 1(rs1)
Server B : Replica Set 2(rs2)
Server C : Configuration Server
Server D : Sharding Router
#
On Server A, rs1 has been set up as follows:
mongod --port 27017 --replSet rs1 --dbpath "/mongo/datadb"
Now the rs1 configuration in mongo shell:
config =
{
_id:"rs1",
members:
[
{ _id:0, host:"Server A IP:27017" },
]
}
rs.initiate( config )
rs.conf()
rs.status()
On Server B , rs2 has been similarly configured.
#
On Server C, the config server has been configured as follows:
mongod --configsvr --port 37017 --dbpath "/rpool/mongo/datadb"
#
Now on Server D, I am running mongos using the following :
mongos --port 27017 --configdb rs1/'Server C IP':37017
When I am trying to open mongo Shell on server D to add the shards using the mongos port and connect to mongos, I am unable to do so. The following error is thrown :
**./mongo --port 27017 --host 'Server C '
MongoDB shell version v3.4.1
connecting to: mongodb://'Server C ip':27017/
2017-11-09T11:21:51.666+0000 W NETWORK [main] Failed to connect to :27017, in(checking socket for error after poll), reason: Connection refused
2017-11-09T11:21:51.686+0000 E QUERY [main] Error: couldn't connect to server 'Server C ip':27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:234:13
#(connect):1:6
exception: connect failed**
When I tried to debug, I found the port 27017 on Server C to be in 'BOUND' state:
netstat -an |grep 27017
*.27017 . 0 0 128000 0 BOUND
'Server ip' stream-ord server ip' 0000000000000000 /tmp/mongodb-27017.sock
Shouldn't mongos occupy this port in Listening mode? Can someone help me in solving this?
Is there any issue with the configuration?

Mongo Sharding got trouble when using vmware

Mongo worked fine when i'm using the local machine.But when i add the shard(established on vmware),i can't do insert operation anymore.
error message:
caused by :: Location28563 cannot send batch write operation to server 192.168.153.132:3000 (192.168.153.132)'. (Response was { "err" : "write results unavailable from 192.168.153.132:3000 :: caused by :: Location28563 cannot send batch write operation to server
config server setup command:
mongod --dbpath=config --port 2222 --bind_ip 0.0.0.0
route server setup command:
mongos --port 3333 --configdb=192.168.153.1:2222 --bind_ip 0.0.0.0
shard server setup command:
mongod --dbpath=Shard1 --port 4444 --bind_ip 0.0.0.0
And i'd done addShard command on the route server.

unable to connect to mongodb on localhost

I have installed MongoDB:
user#user-workshop:~$ sudo service mongodb restart
stop: Unknown instance:
mongodb start/running, process 7980
user#user-workshop:~$ mongo
MongoDB shell version: 2.0.4
connecting to: test
Mon Mar 3 21:43:33 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
user#user-workshop:~$
but as you can see, I'm unable to connect to it. What can I do about it?
Try running these commands:
rm /data/db/mongod.lock
mongod --dbpath /data/db --repair
mongod --dbpath /data/db
For more details read: mongodb manual