Search code examples
mongodbprestotrino

MongoTimeoutException: Error While Using MongoDB with Trino


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


Solution

  • It's working while using this JAVA Code, Use these two mongodb-driver-core-3.7.1-javadoc.jar,mongo-java-driver-3.3.0.jar files to compile and run below code

    import com.mongodb.MongoClient;
    import com.mongodb.MongoClientOptions;
    import com.mongodb.MongoCredential;
    import com.mongodb.ServerAddress;
    import java.util.Collections;
    import org.bson.Document;
    import java.util.List;
    
    public class MongoSession
    {
        public static void main(String[] args)
        {
            ServerAddress seed = new ServerAddress("127.0.0.1:27017");
            MongoCredential credential = MongoCredential.createCredential("user", "database", "password".toCharArray());
            MongoClient client = new MongoClient(seed, Collections.singletonList(credential), MongoClientOptions.builder().build());
            client.getDatabase("database").runCommand(new Document("ping", 1));
            for (String name : client.getDatabase("database").listCollectionNames()) {
                System.out.println(name);
            }
        }
    }
    

    Thanks to MongoDB Community for such a Quick Response

    Jira:- https://jira.mongodb.org/browse/JAVA-4076?focusedCommentId=3673048&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-3673048