Is MongoDB Reader not able to use SSL?

Hei ,

i'm using KNIME Analytics Platform 3.4.2, i instelled the version with all free extensions.

i'm trying to retrieve/read data from a mongodb atlas database. I tried to use the "MongoDB Reader" for the connection to die mondogb.com ATLAS db-cluster.

But it is not working . 'm always ending with the exception

ERROR MongoDB Reader       0:1        Execute failed: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=epic-prod-shard-00-00-ximql.mongodb.net:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.io.EOFException}}]

When i use the same connection details with "robomongo" aka "robo 3T" it is working.

The little difference is, that robo 3 T supports the flag "use SSL protocol" and the authentication method "self-signed certificate".

KNIME does not seem to have any way to enable SSL. Well it's not an option to disable SSL on the mondoDB site.

Does anybody knows a solution or configuration or workaround for this?

Thank you for your help
Best regards,
Michael

 

 

 

Hi Michael,

Call it a bug or a missing feature, but unfortunately it is not possible with the MongoDB Reader node at the moment. As a workaround till this will be fixed I would suggest that you use the Java API (http://api.mongodb.com/java/current/) in a Java Snippet  node. Hope that helps.

Cheers,
Marten

Just to add to this, here is some simple Java Snippet code to connect and insert JSON arrays as documents using the Mongo Java Driver (I’m using mongo-java-driver 3.6.4). This also requires org.json if you don’t have it already, available here.

// Your custom imports:
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;

import com.mongodb.client.MongoDatabase;

import org.json.JSONArray;

   // Enter your code here:
MongoClientURI uri = new MongoClientURI(
    //"mongodb+srv://user:password@clusteruri/"); // for say Mongo Atlas
    "mongodb://localhost:27017"); // for machine address

MongoClient mongoClient = new MongoClient(uri);
MongoDatabase database = mongoClient.getDatabase("mydb");

// c_JSON.toString() is the input from a JSON reader, see attached screenshot
JSONArray jsonArray = new JSONArray(c_JSON.toString());

for(int i = 0; i < jsonArray.length(); i++)
{
      Object object = jsonArray.get(i);
      org.bson.Document document = org.bson.Document.parse(object.toString());
      // collection below from my input variable, can use your own variable or set manually
      database.getCollection(v_DateTimeNumeric).insertOne(document);
}

mongoClient.close();

// expression end

See screenshot for variables. I found that using the Mongo Writer node for looped writing I kept getting native thread errors or GC errors. This method worked for me with none of these issues and you can connect using SSL.

Michael,

Good evening. I solved this using the stunnel proxy from stunnel.org to access a Microsoft Azure COSMOS DB accessible only via an SSL connection:
Steps:

  • install the stunnel proxy from stunnel,org
  • add a section in the stunnel.conf configuration file as follows:

[knime-mongodb]
client = yes
accept = 127.0.0.1:27017
connect = mytestmongodb.documents.azure.com:10255
verifyChain = yes
CAfile = ca-certs.pem
checkHost = mytestmongodb.documents.azure.com

  • Start stunnel by typing stunnel -start
  • Build your knime workflow with the MongoDB reader.
  • Configure mongodb reader to:
  • connect to localhost on port 27017 and
  • set the username and password values.
  • I set the query field to {}

Once executed, knime connects to port 27017 in the clear on the Stunnel input port. Stunnel sets up the encrypted SSL connection to the host specified in the stunnel.conf file on port 10255,

The login credentials are then passed and the result set is returned.

Hope this helps.

Cheers,
Ted

1 Like

HI Marten,
any further development on this thread. or the same work around to be used.

For now you will need to use the work around. I’ll keep you posted.