Can't connect to compose.io mongoDB on bluemix
<p>I'm trying connect to mongoDB but it seems that I can't reach the host.</p>

<p>This problem occurs in mongoshell and pymongo. On shell I use</p>

<pre><code>mongo --ssl --sslAllowInvalidCertificates host:port/db -u user -p pass --sslCAFile ca.pem
</code></pre>

<p>and I get the error message bellow.</p>

<pre><code>MongoDB shell version: 3.2.9
connecting to: host:port/db
2016-09-30T13:41:57.268-0300 W NETWORK  [thread1] Failed to connect to host_ip:port after 5000 milliseconds, giving up.
2016-09-30T13:41:57.323-0300 E QUERY    [thread1] Error: couldn't connect to server host:port, connection attempt failed :
connect@src/mongo/shell/mongo.js:231:14
@(connect):1:6

exception: connect failed
</code></pre>

<p>On pymongo, I connect with the code bellow </p>

<pre><code>Config = configparser.ConfigParser()
Config.read('configurations.cfg')
mongo_conf = Config['mongoDB_test']

connect = "mongodb://%s:%s@%s:%s/%s?ssl=true" \
    %(mongo_conf['user'],mongo_conf['pass'],mongo_conf['host'],mongo_conf['port'],mongo_conf['database'])
client = MongoClient(connect,ssl_ca_certs=mongo_conf['cert'])
db = client[mongo_conf['database']]
</code></pre>

<p>and when I run, I get this</p>

<pre><code>Traceback (most recent call last):
  File "test.py", line 24, in &lt;module&gt;
    db.test.insert_one(data)
  File "/home/jmpf13/repos/laura/dev_env/lib/python3.5/site-packages/pymongo/collection.py", line 627, in insert_one
    with self._socket_for_writes() as sock_info:
  File "/usr/lib/python3.5/contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "/home/jmpf13/repos/laura/dev_env/lib/python3.5/site-packages/pymongo/mongo_client.py", line 762, in _get_socket
    server = self._get_topology().select_server(selector)
  File "/home/jmpf13/repos/laura/dev_env/lib/python3.5/site-packages/pymongo/topology.py", line 210, in select_server
    address))
  File "/home/jmpf13/repos/laura/dev_env/lib/python3.5/site-packages/pymongo/topology.py", line 186, in select_servers
    self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: host:port: timed out 
</code></pre>

<p>I've just connected to a mongoDB instance I've deployed to bluemix using mongo shell with similar syntax to what you've used, and it works fine.</p>

<p>There might be a problem with your deployment.
In the bluemix ui, when you open your mongo service, does the "Status" indicator appear green?</p>

<p>The other thing I would do is try to verify that host is reachable on that port. For instance, using something like tcping:
<code>tcping &lt;host&gt; &lt;port&gt;</code></p>

<p>Or, if in a pinch, telnet to the port:
<code>telnet &lt;host&gt; &lt;port&gt;</code>
For the latter you'll get something like:</p>

<p><code>Trying &lt;ip&gt;...
Connected to &lt;host&gt;.
Escape character is '^]'.</code></p>

<p>If any of these fail, I'd make sure nothing on your end is blocking the traffic and then reach out to support in case your deployment did not provision correctly or otherwise has issues.</p>

python mongodb ibm-bluemix pymongo compose