connecting to mongodb with ipv6 via mongo shell - mongodb

I was able to enable ipv6 on mongodb.
/etc/mongod.conf file has net.ipv6 set to true.
I can see that mongodb is listening on ipv6:
# netstat -anp | grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 17967/mongod
tcp6 0 0 :::27017 :::* LISTEN 17967/mongod
unix 2 [ ACC ] STREAM LISTENING 19750206 17967/mongod /tmp/mongodb-27017.sock
#
ping6 to the IPv6 address is fine.
[root#tesla05 log]# ping6 -I eno33554952 tesla05-2-ipv6.ulticom.com
PING tesla05-2-ipv6.ulticom.com(tesla05) from fe80::250:56ff:feb4:7c43 eno33554952: 56 data bytes
64 bytes from tesla05: icmp_seq=1 ttl=64 time=0.101 ms
64 bytes from tesla05: icmp_seq=2 ttl=64 time=0.093 ms
64 bytes from tesla05: icmp_seq=3 ttl=64 time=0.091 ms
however, mongo shell doesn't seem to understand ipv6 address.
[root#tesla05 log]# mongo --ipv6 [fe80::250:56ff:feb4:7c43]:27017/admin
MongoDB shell version: 3.2.4
connecting to: [fe80::250:56ff:feb4:7c43]:27017/admin
2016-10-25T12:04:50.401-0400 W NETWORK [thread1] Failed to connect to fe80::250:56ff:feb4:7c43:27017, reason: errno:22 Invalid argument
2016-10-25T12:04:50.402-0400 E QUERY [thread1] Error: couldn't connect to server [fe80::250:56ff:feb4:7c43]:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:226:14
#(connect):1:6
exception: connect failed
[root#tesla05 log]# mongo --ipv6 tesla05-2-ipv6.ulticom.com:27017/admin
MongoDB shell version: 3.2.4
connecting to: tesla05-2-ipv6.ulticom.com:27017/admin
2016-10-25T12:15:17.861-0400 W NETWORK [thread1] Failed to connect to fe80::250:56ff:feb4:7c43:27017, reason: errno:22 Invalid argument
2016-10-25T12:15:17.861-0400 E QUERY [thread1] Error: couldn't connect to server tesla05-2-ipv6.ulticom.com:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:226:14
#(connect):1:6
exception: connect failed

You are trying to use a link-local IPv6 address. These are not valid without a scope, but you haven't provided one. Thus you get the error Invalid argument. For this reason, putting a link-local address in the DNS makes no sense, because the address is only valid on a particular LAN, and the scope may be different for every host on that LAN.
To use the address, append the scope to it, e.g. fe80::250:56ff:feb4:7c43%eno33554952

Related

MongoDB, remote connection failing

I'm trying to connect to mongoDB server running in another AWS Account from my other AWS account to refresh the content.
I'm getting an error.
I NETWORK [thread1] Socket recv() errno:104 Connection reset by peer mongo_db_server:27017
I NETWORK [thread1] SocketException: remote: (NONE):0 error: 9001 socket exception [RECV_ERROR] server [mongodb_db_server:27017]
2021-01-14T23:26:26.015-0500 E QUERY [thread1] Error: network error while attempting to run command 'isMaster' on host 'mongodb_db_server:27017' :
connect#src/mongo/shell/mongo.js:231:14
#(connect):1:6
Remote MongoDB server config has
net:
port: 27017
bindIp: 0.0.0.0
Security groups allow connection to 27017 from 0.0.0.0/0 fo testing purpose.
what am i missing?
It was due to network connectivity.

Cannot (remote) connect Mac mongo client to Raspberry pi mongod

I am running the "default" mongodb on the Rasp Pi. I cannot connect to mongod running on my Raspberry Pi from my Mac running a mongo client. I can connect to the web page (my ip:28017...http://192.168.86.20:28017/). I made all the tweeks on the Raspberry pi I needed to make (opening the ports (results below), modification to mongodb.conf bind_ip parameter (see below).
Why am I not able to connect from my Mac client? Thank you.
The error I get through the mongo client on the Mac is:
$ mongo --host 192.168.86.20
MongoDB shell version v4.2.3
connecting to: mongodb://192.168.86.20:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-02-09T03:56:39.564-0800 E QUERY [js] Error: couldn't connect to server 192.168.86.20:27017, connection attempt failed: SocketException: Error connecting to 192.168.86.20:27017 :: caused by :: Operation timed out :
connect#src/mongo/shell/mongo.js:341:17
#(connect):2:6
2020-02-09T03:56:39.568-0800 F - [main] exception: connect failed
2020-02-09T03:56:39.568-0800 E - [main] exiting with code 1
Version of mongod on Raspberry pi:
> db.version()
2.4.14
version of mongo client on mac:
$ mongo
MongoDB shell version v4.2.0
Raspberry Pi:
$ cat /proc/cpuinfo | grep 'Model'
Model : Raspberry Pi 3 Model B Rev 1.2
Version of Raspbian:
$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
The ports are available:
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:28017 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
The mongodb.conf bind_ip has been set:
#bind_ip = 127.0.0.1
bind_ip = 0.0.0.0
#port = 27017

MacOS Catalina Wont connect to MONGODB Server on Google Compute Engine

I have a problems on my Macbook 15" Catalina to access Mongodb run in docker compute engine. If i use other laptop connection work well without error or with other os like ubuntu or windows that no problems. Cant connect just in my macbook 15" with os Catalina.
Error on mongo command :
▶mongo [PublicIP-VMInstance]:[PortMongo]/admin -u username -p password
MongoDB shell version v3.6.14
connecting to: mongodb://[PublicIP-VMInstance]:[PortMongo]/admin?gssapiServiceName=mongodb
2019-11-23T18:22:30.975+0700 I NETWORK [thread1] Socket recv() Connection reset by peer [PublicIP-VMInstance]:[PortMongo]
2019-11-23T18:22:30.975+0700 I NETWORK [thread1] SocketException: remote: (NONE):0 error: SocketException socket exception [RECV_ERROR] server [[PublicIP-VMInstance]:[PortMongo]]
2019-11-23T18:22:30.975+0700 E QUERY [thread1] Error: network error while attempting to run command 'isMaster' on host '[PublicIP-VMInstance]:[PortMongo]' :
connect#src/mongo/shell/mongo.js:263:13
#(connect):1:6
exception: connect failed
show error if i use --ssl flag :
▶mongo [PublicIP-VMInstance]:[PortMongo]/admin -u username -p password --ssl --verbose
MongoDB shell version v3.6.14
connecting to: mongodb://[PublicIP-VMInstance]:[PortMongo]/admin?gssapiServiceName=mongodb
2019-11-23T11:47:19.836+0700 D NETWORK [thread1] creating new connection to:[PublicIP-VMInstance]:[PortMongo]
2019-11-23T11:47:19.839+0700 I NETWORK [thread1] Socket recv() Connection reset by peer [PublicIP-VMInstance]:[PortMongo]
2019-11-23T11:47:19.839+0700 E QUERY [thread1] Error: socket exception [RECV_ERROR] for [PublicIP-VMInstance]:[PortMongo] :
connect#src/mongo/shell/mongo.js:263:13
#(connect):1:6
2019-11-23T11:47:19.839+0700 D - [thread1] User Assertion: 12513:connect failed src/mongo/shell/shell_utils.cpp 279
2019-11-23T11:47:19.839+0700 I QUERY [thread1] MozJS GC prologue heap stats - total: 3447601 limit: 0
2019-11-23T11:47:19.840+0700 I QUERY [thread1] MozJS GC epilogue heap stats - total: 1641 limit: 0
2019-11-23T11:47:19.840+0700 I QUERY [thread1] MozJS GC prologue heap stats - total: 3937 limit: 0
2019-11-23T11:47:19.841+0700 I QUERY [thread1] MozJS GC epilogue heap stats - total: 9 limit: 0
2019-11-23T11:47:19.841+0700 D - [main] User Assertion: 12513:connect failed src/mongo/scripting/mozjs/proxyscope.cpp 302
exception: connect failed
If use GUI Client like NoSQLBooster show error :
12:53:53.307 *** Starting MongoClient.connect ***
{"options":{"appname":"NoSQLBoosterV5.2.7_125336.468","autoReconnect":true,"keepAlive":60000,"poolSize":0,"promoteLongs":false,"promoteValues":false,"reconnectTries":172800,"socketTimeoutMS":0,"sslValidate":false,"useNewUrlParser":true},"uri":"mongodb://username:******#IPPublic-VMInstance:PORTMONGO?authSource=admin"}
12:53:53.311 *** Connect Error ***
{"errorLabels":["TransientTransactionError"],"message":"failed to connect to server [IPPublic-VMInstance:PORTMONGO] on first connect [MongoNetworkError: read ECONNRESET]","name":"MongoNetworkError","stack":"MongoNetworkError: failed to connect to server [IPPublic-VMInstance:PORTMONGO] on first connect [MongoNetworkError: read ECONNRESET]\n at Pool.<anonymous> (/Applications/NoSQLBooster for MongoDB.app/Contents/Resources/app.asar/node_modules/mongodb-core/lib/topologies/server.js:431:11)\n at Pool.emit (events.js:182:13)\n at connect (/Applications/NoSQLBooster for MongoDB.app/Contents/Resources/app.asar/node_modules/mongodb-core/lib/connection/pool.js:557:14)\n at callback (/Applications/NoSQLBooster for MongoDB.app/Contents/Resources/app.asar/node_modules/mongodb-core/lib/connection/connect.js:109:5)\n at runCommand (/Applications/NoSQLBooster for MongoDB.app/Contents/Resources/app.asar/node_modules/mongodb-core/lib/connection/connect.js:129:7)\n at Connection.errorHandler (/Applications/NoSQLBooster for MongoDB.app/Contents/Resources/app.asar/node_modules/mongodb-core/lib/connection/connect.js:321:5)\n at Object.onceWrapper (events.js:273:13)\n at Connection.emit (events.js:182:13)\n at Socket.<anonymous> (/Applications/NoSQLBooster for MongoDB.app/Contents/Resources/app.asar/node_modules/mongodb-core/lib/connection/connection.js:321:10)\n at Object.onceWrapper (events.js:273:13)\n at Socket.emit (events.js:182:13)\n at emitErrorNT (internal/streams/destroy.js:82:8)\n at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)\n at process._tickCallback (internal/process/next_tick.js:63:19)"}
I have try with this tutorial :
openssl problems
https://community.exploratory.io/t/mongodb-ssl-connection-error-on-mac-os-x/832 [ still not working ]
use --ssl but in other laptop work well without this options
Apple has made TLS requirements stricter in Catalina. I have a similar case where the connection from Catalina fails using the mongo cli client. I couldn't find statements about changes in behavior of SSL specifically (which I am using). They may have changed something they didn't communicate.
About Catalina TLS changes: https://support.apple.com/en-us/HT210176
If I run a VM Ubuntu on Catalina, I'm able to connect from there. Also macs with Mojave can connect just fine using the same certificates, keys, and network.
Below is the error I'm seeing. It's slightly different to yours but also something that only happens on Catalina.
mongo --host myhost.com --ssl --sslCAFile ca.pem --sslPEMKeyFile client.pem -u myuser -p
W CONTROL [main] Option: ssl is deprecated. Please use tls instead.
W CONTROL [main] Option: sslPEMKeyFile is deprecated. Please use tlsCertificateKeyFile instead.
W CONTROL [main] Option: sslCAFile is deprecated. Please use tlsCAFile instead.
MongoDB shell version v4.2.1
Enter password:
connecting to: mongodb://myhost.com:27017/?compressors=disabled&gssapiServiceName=mongodb
E NETWORK [js] SSL peer certificate validation failed: Certificate trust failure: Host name mismatch; connection rejected
E QUERY [js] Error: couldn't connect to server myhost.com:27017, connection attempt failed: SSLHandshakeFailed:
SSL peer certificate validation failed: Certificate trust failure: Host name mismatch; connection rejected :
connect#src/mongo/shell/mongo.js:341:17
#(connect):2:6
F - [main] exception: connect failed
E - [main] exiting with code 1
I suggest you try generating new certificates that match Apple's new requirements if that's at all possible. Another thing you could try would be to run a Linux VM on your Mac and see if the connection works from there. If it does, I reckon it would narrow the issue down to the certificates themselves.
Update: Docker seems to be an alternative for the VM. Using a Docker container on a Mac with Catalina I can connect to mongo just fine.
Are you certain that PublicIP-VMInstance and PortMongo are resolving to IP addresses and a port by your mongo client? I'm running MacOS X 10.15.1 (Catalina) and Mongo client 4.2.1 and connections work perfectly for me using a connection string like this:
/opt/local/bin/mongo --ssl --sslAllowInvalidCertificates --host=mongo.mydomain.com:27017 -u mongoMatt -p dont*You*Wish

Why mongodb connection url is not compatible for shell and driver?

I use this connection url to connect mongodb instance through driver: mongodb://localhost:27017?ssl=true and it works fine. But the same url doesn't work on mongo-shell instead I have to take out the ssl=true parameter and use mongo mongodb://localhost:27017 --ssl command. Why isn't they compatible with each other? Is there a universal url for both types of connections?
EDIT1
I have tried with mongo 3.4.3 and 3.4.2. Both version have the same issue.
Below is the detailed command and output I got:
mongo mongodb://host-1:27017,host-2:27017,host3:27017/admin?replicaSet=Cluster0-shard-0&ssl=true --username admin --password 123456
Below is the output:
connecting to: mongodb://host-1:27017,host-2:27017,host-3:27017/admin?replicaSet=Cluster0-shard-0
2017-04-10T20:52:09.345+1000 I NETWORK [thread1] Starting new replica set monitor for Cluster0-shard-0/host-1:27017,host-2:27017,host-3:27017
2017-04-10T20:52:09.416+1000 I NETWORK [thread1] Socket recv() Connection reset by peer 13.54.24.198:27017
2017-04-10T20:52:09.416+1000 I NETWORK [thread1] SocketException: remote: (NONE):0 error: 9001 socket exception [RECV_ERROR] server [13.54.24.198:27017]
2017-04-10T20:52:09.416+1000 W NETWORK [thread1] No primary detected for set Cluster0-shard-0
2017-04-10T20:52:09.416+1000 I NETWORK [thread1] All nodes for set Cluster0-shard-0 are down. This has happened for 1 checks in a row.
2017-04-10T20:52:09.987+1000 I NETWORK [thread1] Socket recv() Connection reset by peer 13.54.31.109:27017
2017-04-10T20:52:09.987+1000 I NETWORK [thread1] SocketException: remote: (NONE):0 error: 9001 socket exception [RECV_ERROR] server [13.54.31.109:27017]
2017-04-10T20:52:10.019+1000 W NETWORK [thread1] No primary detected for set Cluster0-shard-0
2017-04-10T20:52:10.019+1000 I NETWORK [thread1] All nodes for set Cluster0-sha
rd-0 are down. This has happened for 2 checks in a row.
2017-04-10T20:52:10.558+1000 I NETWORK [thread1] Socket recv() Connection reset
...
2017-04-10T20:53:44.940+1000 I NETWORK [ReplicaSetMonitor-TaskExecutor-0] SocketException: remote: (NONE):0 error: 9001 socket exception [RECV_ERROR] server [13.54.31.109:27017]
This should be fixed if you use mongo shell version >= 3.4.
Assuming that you are connecting using a 3.4 shell, the command line and the output would look something like this:
mongo "mongodb://localhost:27017/test?ssl=true" --authenticationDatabase admin --username xxx --password xxx
MongoDB shell version v3.4.3
connecting to: mongodb://localhost:27017/test?ssl=true
MongoDB server version: 3.4.3
>

Ubuntu can't use node to run mongod database

ubuntu#ip-172-31-45-35:~/cse303.p2$ node qloader.js
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [52.33.215.205:27017]
at null.<anonymous> (/home/ubuntu/cse303.p2/node_modules/mongoose/node_modules/mongodb/lib/mong odb/connection/server.js:556:74)
at EventEmitter.emit (events.js:106:17)
at null.<anonymous> (/home/ubuntu/cse303.p2/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:156:15)
at EventEmitter.emit (events.js:98:17)
at Socket.<anonymous> (/home/ubuntu/cse303.p2/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:415:13)
above is the error message i got when trying to do 'node' to run my database.
I have set all my security group to 'all traffic', I suppose it's not a problem with my security group.
When I ping that ip address it can connect, this is what is shows.
ubuntu#ip-172-31-45-35:~/cse303.p2$ ping 52.33.215.205
PING 52.33.215.205 (52.33.215.205) 56(84) bytes of data.
64 bytes from 52.33.215.205: icmp_seq=1 ttl=63 time=1.37 ms
64 bytes from 52.33.215.205: icmp_seq=2 ttl=63 time=1.27 ms
64 bytes from 52.33.215.205: icmp_seq=3 ttl=63 time=1.21 ms
64 bytes from 52.33.215.205: icmp_seq=4 ttl=63 time=1.25 ms
^C
--- 52.33.215.205 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 1.218/1.281/1.376/0.072 ms
So it can connect to that address, but when i add that port 27017, it does't work.
ubuntu#ip-172-31-45-35:~/cse303.p2$ ping 52.33.215.205:27017
ping: unknown host 52.33.215.205:27017
I am not sure whether my mongod is running properly, this is what i got.
ubuntu#ip-172-31-22-135:~$ sudo service mongodb start
mongodb start/running, process 1382
You can't ping a port. Ping is ICMP and not TCP or UDP. The line mongodb start/running, process 1382 indicates that MongoDB is running.
It is likely that MongoDB's bind IP is set to 127.0.0.1. In the MongoDB configuration, check the value of bind_ip. It is likely set to localhost (127.0.0.1) and thus will only accept connections from the local VM.
There are many guides out there that can help, such as this or this.