I was asked this question on https://stackoverflow.com/questions/54487413/usage-of-hibernate-ogm-with-cloud-mongodb-atlas-m0-free-tier/54532599#54532599
I am trying to use MongoDB Atlas M0 (Free Tier) for my JAVA EE application, now I am using:
Local MongoDB database (v4.0.4)
Hibernate Core "hibernate-core 5.3.6.Final"
Hibernate OGM "hibernate-ogm-mongodb 5.3.1.Final"
Java application server WildFly 15.0.0.Final
When I tried to connect Hibernate with Mongo Atlas to test cloud database, I am was not able to have a working connection, because mongodb driver throws an exception com.mongodb.MongoSocketReadException: Prematurely reached end of stream
My persistence.xml that causes the error:
As @Davide D'Alto suggested I create Factory to interact for the persistence unit
Sorry, I cannot understand form the description... Are you saying that using that the creations of a custom `MongoDBDatastoreProvider` that uses `MongoClients.create(...)` worked for you? Thanks
Hi Davide!
I am now on it, trying to use 'MYCustomMongoDBDatastoreProvider' like you suggested to me! I am not very familiar with this kind of using of connection, that's why it takes a bit of time for me. Thank you for your help!
Sure, make sure once you have created the class to change this property:
to something like this:
yeah, got it! And then I've created this class MYCustomMongoDBDatastoreProvider and then overrode createMongoClient and tried create MongoClient just simple like this to connect to one node:
or this to connect to the cluster of 3 nodes:
But nothing changed, like before I was received the same error:
Hi Davide!
I was investigating a little bit more a I believe I found the problem. Finally I was able to make connection from my own MYCustomMongoDBDatastoreProvider (that you suggested me) only with make a connection with MongoClientOptions option sslEnabled(true), to do this I should create MongoClient and pass to it all options and configs like this:
So without sslEnabled(true) I had the same error as before, but with it works fine.
And I also found this issue https://github.com/metabase/metabase/issues/6678 where people had the same problems and as I was able to understand, they spoke about SSL problem too.
In fact here https://docs.atlas.mongodb.com/driver-connection/ - "Connect via Driver" there is Prerequisites:
I can't do objective conclusions, but may be this error is throws by lack of implementation SSL.