[JAVA-4076] MongoTimeoutException: Error While Using MongoDB with Trino Created: 19/Mar/21  Updated: 26/Sep/22  Resolved: 19/Mar/21

Status: Closed
Project: Java Driver
Component/s: Connection Management
Affects Version/s: 3.6.0
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Abhaypratap singh Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu,Trino


Attachments: JPEG File WhatsApp Image 2021-03-18 at 11.22.58 AM.jpeg     JPEG File WhatsApp Image 2021-03-18 at 6.20.19 PM.jpeg    

 Description   

 
I'm passing mongodb.properties as

connector.name=mongodb mongodb.seeds=127.0.0.1:27017 mongodb.credentials=username:password@database

But when running the catalog after passing the query it is giving error as
 {{Query 20210312_110147_00003_zxyd4 failed: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@469d4507. Client view of cluster state is {type=REPLICA_SET, servers=[

{address=hostname:27017, type=UNKNOWN, state=CONNECTING, exception=\{com.mongodb.MongoSocketOpenException: Exception opening socket}

, caused by {java.net.SocketTimeoutException: connect timed out}}]}}
Can Someone Help. Am i doing something wrong while doing the connection?

Note:- I'm running trino locally using single machine for testing, that functions as both a coordinator and worker and mongodb is on some other server but i'm routing the localhost to the desired server using ssh

Slack Users can follow this thread :- https://trinodb.slack.com/archives/CGB0QHWSW/p1615977203044600



 Comments   
Comment by Jeffrey Yemin [ 19/Mar/21 ]

I'm going to close this issue now as I think I've answered your questions about the MongoDB Java driver itself, but in case you need additional support I wanted to give you some resources to get any further question answered:

  • Our MongoDB support portal, located at support.mongodb.com
  • Our MongoDB community portal, located here
  • If you are an Atlas customer, you can review your support options by clicking Support in the top menu bar of the Atlas UI
Comment by Jeffrey Sposetti [ 19/Mar/21 ]

Hi abhaypratap.singh@capfront.in,

Not sure exactly but here goes...when configuring the MongoDB connector in Trino, in addition to setting the mongodb.seeds list, you may also need to set mongodb.required-replica-set property.

https://trino.io/docs/current/connector/mongodb.html 

Don't know if this is the exact right spot (not deeply familiar with the MongoDB connector), but it's using those properties to instantiate the MongoClient... (folks in the Trino / Presto community may know better):

https://github.com/prestodb/presto/blob/master/presto-mongodb/src/main/java/com/facebook/presto/mongodb/MongoClientModule.java#L71 

Unrelated question: are you just primarily looking to get SQL access to MongoDB? Or are you using Trino for other things? Just for what it's worth if it's just SQL access to MDB, you can try this BI Connector:

https://docs.mongodb.com/bi-connector/current/

Hope this helps!

Jeff

Comment by Abhaypratap singh [ 19/Mar/21 ]

Hi Jeffrey Yemin,

Thanks for helping out, yes the above code snippet which you sent is working 

But i want to use the mongodb in trino (presto sql) if you could help me with that also it'll be great

Comment by Jeffrey Yemin [ 19/Mar/21 ]

Hi abhaypratap.singh@capfront.in,

I'm afraid that this is not going to work if your application is trying to connect to a replica set. That's because drivers are required to discover all the servers in the replica set in order to determine which is the primary, and in doing so tries to connect using the hostnames that are known to the replica set, discarding the hostname from the original seed list. To test this hypothesis, try connecting with this code instead:

        ServerAddress seed = new ServerAddress("localhost:27017");
        MongoCredential credential = MongoCredential.createCredential("user", "database", "password".toCharArray());
        MongoClient client = new MongoClient(seed, credential, MongoClientOptions.builder().build());
        client.getDatabase("database").runCommand(new Document("ping", 1));

This will create a direct connection to localhost:27017 and not do discovery.

Let me know if that works, and if so, we can determine next steps based on the requirements of your application.

Comment by Abhaypratap singh [ 19/Mar/21 ]

This is also not working 

import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import java.util.Arrays;
import java.util.List;
public class MongoSession
{
public static void main(String[] args) {
List<ServerAddress> seeds = Arrays.asList(new ServerAddress("localhost:27017"));
List<MongoCredential> credentials =Arrays.asList(MongoCredential.createCredential("user", "database", "password".toCharArray()));
MongoClient client = new MongoClient(seeds, credentials, MongoClientOptions.builder().build());
client.getDatabase("database");
}
}

 

Generated at Thu Feb 08 09:01:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.