Using Mongo-cli to connect to an OpenShift database - mongodb

I'm trying to connect to a database created onto OpenShift from a cartridge and I'm having issues connecting through it using Mongo client from shell.
I'm using Mac OS Sierra as a client and my Mongo project is hosted onto MiniShift. I can connect locally using OpenShift shell :
mongo sampledb --host localhost -u user -p password
But when I try to connect from MacOS directly :
mongo sampledb --host devmongo-mongo01.192.168.99.100.nip.io -u user -p password
I got this error stack with verbose mode activated:
2017-08-17T18:10:41.938+0200 D NETWORK [thread1] creating new connection to:devmongo-mongo01.192.168.99.100.nip.io:27017
2017-08-17T18:10:41.941+0200 W NETWORK [thread1] Failed to connect to 192.168.99.100:27017, in(checking socket for error after poll), reason: Connection refused
2017-08-17T18:10:41.941+0200 D - [thread1] User Assertion: 1:couldn't connect to server devmongo-mongo01.192.168.99.100.nip.io:27017, connection attempt failed src/mongo/scripting/mozjs/mongo.cpp 716
2017-08-17T18:10:41.941+0200 E QUERY [thread1] Error: couldn't connect to server devmongo-mongo01.192.168.99.100.nip.io:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:237:13
#(connect):1:6
2017-08-17T18:10:41.941+0200 D - [thread1] User Assertion: 12513:connect failed src/mongo/shell/shell_utils.cpp 256
2017-08-17T18:10:41.941+0200 I QUERY [thread1] MozJS GC prologue heap stats - total: 3498847 limit: 0
2017-08-17T18:10:41.943+0200 I QUERY [thread1] MozJS GC epilogue heap stats - total: 350087 limit: 0
2017-08-17T18:10:41.943+0200 I QUERY [thread1] MozJS GC prologue heap stats - total: 241791 limit: 0
2017-08-17T18:10:41.944+0200 I QUERY [thread1] MozJS GC epilogue heap stats - total: 50423 limit: 0
2017-08-17T18:10:41.944+0200 D - [main] User Assertion: 12513:connect failed src/mongo/scripting/mozjs/proxyscope.cpp 295
exception: connect failed

I realized that it was not possible to edit "bind_ip" after deployment of MongoDB on OpenShift (so not possible to access MongoDB via a tool such a Robomongo). So my solution to use a Mongo Database in an OpenShift project, was to embed the projects that use the DB in same project and using connection String with service to identify the Database container instead of IP because if container is restarted, the IP can be changed but the service will remain the same.

Related

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

mongodb exception connection failed

when I'm trying to open mongodb with command prompt I'm getting a error message like
D:\mongo-bd\bin>mongo.exe
MongoDB shell version v3.6.4
connecting to: mongodb://127.0.0.1:27017
2018-04-27T18:50:28.340+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1
:27017 after 5000ms milliseconds, giving up.
2018-04-27T18:50:28.340+0530 E QUERY [thread1] Error: couldn't connect to ser
ver 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
I have tried by running mongo --repair command but still I'm facing this problem.
1 First set up the data directory - google it
2 then run the
{installationDirectory}/MongoDB/Server/{serverVersion}/bin/mongod.exe
to start the service
3 Get into the shell
{installationDirectory}/MongoDB/Server/{serverVersion}/bin/mongo.exe

mongodb installation error connection failed on windows

I have tried all solutions mentioned in below 2 links
Mongodb: Failed to connect to 127.0.0.1:27017, reason: errno:10061
How to start mongo db on windows
But still getting below error
`C:\Program Files (x86)\MongoDB\Server\3.2\bin>mongo MongoDB shell
version: 3.2.18-15-g678cb63 connecting to: test
2018-01-26T16:39:23.926+0530 W NETWORK [thread1] Failed to connect to
127.0.0.1 :27017 after 5000ms milliseconds, giving up. 2018-01-26T16:39:23.927+0530 E QUERY [thread1] Error: couldn't
connect to ser ver 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14 #(connect):1:6
exception: connect failed`
Open onemore terminal as admin and run mongod. After this you can start your app in main terminal.

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
>

Could not connect to mongodb. errno:111 Connection refused

I am using mongodb on ubuntu-16.04 but mongodb give server connection error:
MongoDB shell version: 3.2.9 connecting to: test
2016-09-23T12:01:10.258+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-09-23T12:01:10.286+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
What can I do?
looks like your mongod process is not running on port 27017. Make sure your mongod process is running maybe verify with linux command.
If you start mongod process and even then it's failing to connect with mongo command, it means it's failing to intialize, check out designated mongo log file for the reason