title: How to connect Presto to Mongodb container
body: <p><strong>Problem: Can't connect presto container to mongodb container.</strong></p>
  
  <p>I have three running containers:</p>
  
  <pre><code>    [root@localhost tmp]# docker container ls
  CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                      NAMES
  8f6686547c55        mongo               "docker-entrypoint.s…"   6 minutes ago       Up 6 minutes        0.0.0.0:27017-&gt;27017/tcp   tmp_mongo_1
  0b639ef12c12        mongo-express       "tini -- /docker-ent…"   6 minutes ago       Up 6 minutes        0.0.0.0:8081-&gt;8081/tcp     tmp_mongo-express_1
  c51178e29a3e        prestosql/presto    "/usr/lib/presto/bin…"   4 days ago          Up About an hour    0.0.0.0:8080-&gt;8080/tcp     presto
  </code></pre>
  
  <p>presto container can access mongo db (network-wise):</p>
  
  <pre><code>[root@c51178e29a3e /]# ping mongo
  PING mongo (172.20.0.3) 56(84) bytes of data.
  64 bytes from tmp_mongo_1.tmp_default (172.20.0.3): icmp_seq=1 ttl=64 time=0.130 ms
  64 bytes from tmp_mongo_1.tmp_default (172.20.0.3): icmp_seq=2 ttl=64 time=0.108 ms
  </code></pre>
  
  <p>Presto properties configured as well (/usr/lib/presto/default/etc/catalog/mongodb.properties):</p>
  
  <pre><code>connector.name=mongodb
  mongodb.seeds=mongo:27017
  mongodb.credentials=root:example@liran
  </code></pre>
  
  <p>The "liran" collection exist:
  <a href="https://i.stack.imgur.com/b0w47.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b0w47.png" alt="enter image description here"></a></p>
  
  <p>When trying to access mongo's "liran" collection:</p>
  
  <pre><code>    presto&gt; SELECT COUNT(*) FROM mongodb.local.liran;
  Query 20191216_154753_00000_sz73z failed: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=mongo:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='root', source='liran', password=&lt;hidden&gt;, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server mongo:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }}}]
  </code></pre>
  
  <p>while on mongo I get:</p>
  
  <pre><code>    mongo_1          | 2019-12-16T15:51:00.795+0000 I  NETWORK  [conn322] end connection 172.20.0.4:34810 (4 connections now open)
  mongo_1          | 2019-12-16T15:51:10.796+0000 I  NETWORK  [listener] connection accepted from 172.20.0.4:34812 #323 (5 connections now open)
  mongo_1          | 2019-12-16T15:51:10.796+0000 I  NETWORK  [conn323] received client metadata from 172.20.0.4:34812 conn323: { driver: { name: "mongo-java-driver", version: "3.6.0" }, os: { type: "Linux", name: "Linux", architecture: "amd64", version: "3.10.0-862.11.6.el7.x86_64" }, platform: "Java/Oracle Corporation/11.0.4+11-LTS" }
  mongo_1          | 2019-12-16T15:51:10.798+0000 I  ACCESS   [conn323] SASL SCRAM-SHA-1 authentication failed for root on liran from client 172.20.0.4:34812 ; UserNotFound: Could not find user "root" for db "liran"
  mongo_1          | 2019-12-16T15:51:10.799+0000 I  NETWORK  [conn323] end connection 172.20.0.4:34812 (4 connections now open)
  mongo_1          | 2019-12-16T15:51:20.800+0000 I  NETWORK  [listener] connection accepted from 172.20.0.4:34818 #324 (5 connections now open)
  mongo_1          | 2019-12-16T15:51:20.801+0000 I  NETWORK  [conn324] received client metadata from 172.20.0.4:34818 conn324: { driver: { name: "mongo-java-driver", version: "3.6.0" }, os: { type: "Linux", name: "Linux", architecture: "amd64", version: "3.10.0-862.11.6.el7.x86_64" }, platform: "Java/Oracle Corporation/11.0.4+11-LTS" }
  mongo_1          | 2019-12-16T15:51:20.803+0000 I  ACCESS   [conn324] SASL SCRAM-SHA-1 authentication failed for root on liran from client 172.20.0.4:34818 ; UserNotFound: Could not find user "root" for db "liran"
  mongo_1          | 2019-12-16T15:51:20.804+0000 I  NETWORK  [conn324] end connection 172.20.0.4:34818 (4 connections now open)
  mongo_1          | 2019-12-16T15:51:30.806+0000 I  NETWORK  [listener] connection accepted from 172.20.0.4:34820 #325 (5 connections now open)
  mongo_1          | 2019-12-16T15:51:30.807+0000 I  NETWORK  [conn325] received client metadata from 172.20.0.4:34820 conn325: { driver: { name: "mongo-java-driver", version: "3.6.0" }, os: { type: "Linux", name: "Linux", architecture: "amd64", version: "3.10.0-862.11.6.el7.x86_64" }, platform: "Java/Oracle Corporation/11.0.4+11-LTS" }
  mongo_1          | 2019-12-16T15:51:30.809+0000 I  ACCESS   [conn325] SASL SCRAM-SHA-1 authentication failed for root on liran from client 172.20.0.4:34820 ; UserNotFound: Could not find user "root" for db "liran"
  mongo_1          | 2019-12-16T15:51:30.810+0000 I  NETWORK  [conn325] end connection 172.20.0.4:34820 (4 connections now open)
  mongo_1          | 2019-12-16T15:51:40.811+0000 I  NETWORK  [listener] connection accepted from 172.20.0.4:34822 #326 (5 connections now open)
  mongo_1          | 2019-12-16T15:51:40.812+0000 I  NETWORK  [conn326] received client metadata from 172.20.0.4:34822 conn326: { driver: { name: "mongo-java-driver", version: "3.6.0" }, os: { type: "Linux", name: "Linux", architecture: "amd64", version: "3.10.0-862.11.6.el7.x86_64" }, platform: "Java/Oracle Corporation/11.0.4+11-LTS" }
  mongo_1          | 2019-12-16T15:51:40.814+0000 I  ACCESS   [conn326] SASL SCRAM-SHA-1 authentication failed for root on liran from client 172.20.0.4:34822 ; UserNotFound: Could not find user "root" for db "liran"
  </code></pre>
  
  <p>changing the mongodb.credentials=root:example@local just gives the same error with local instead of liran.</p>
  
  <p>One last thing, when I ran the mongo containers I have used the following stack.yml:</p>
  
  <pre><code>    [root@localhost tmp]# cat stack.yml 
  
  # Use root/example as user/password credentials
  version: '3.1'
  
  services:
  
    mongo:
      image: mongo
      restart: always
      ports:
        - 27017:27017
      environment:
        MONGO_INITDB_ROOT_USERNAME: root
        MONGO_INITDB_ROOT_PASSWORD: example
        net.tls.mode: disabled
  
    mongo-express:
      image: mongo-express
      restart: always
      ports:
        - 8081:8081
      environment:
        ME_CONFIG_MONGODB_ADMINUSERNAME: root
        ME_CONFIG_MONGODB_ADMINPASSWORD: example
  </code></pre>
  
  <p>The dockers being used: 
  <a href="https://hub.docker.com/_/mongo" rel="nofollow noreferrer">mongo</a>, <a href="https://hub.docker.com/r/prestosql/presto" rel="nofollow noreferrer">presto</a></p>