Connection with Eclipselink (JPA) to Atlas

I would like to connect to my Atlas cluster using eclipselinks nosql feature. I manage to connect to a local mongodb using this persistance.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="" xmlns:xsi="" xsi:schemalocation="">
    <persistence-unit name="mongo-test" transaction-type="RESOURCE_LOCAL">
            <property name="" value="org.eclipse.persistence.nosql.adapters.mongo.MongoPlatform"/>
            <property name="eclipselink.nosql.connection-spec" value="org.eclipse.persistence.nosql.adapters.mongo.MongoConnectionSpec"/>
            <property name="" value="27017"/>
            <property name="" value="localhost"/>
            <property name="" value="xrn-testing"/>
            <property name="eclipselink.logging.level" value="FINEST"/>

However from Atlas I just get a connection string which looks like this:


Question: How do I need to set up my persistence.xml to connect to the cluster. In particular:

  • what’s the port? Is it still 27017? Do I need to provide it at all?
  • is the correct host? What about the query string?
  • how to correctly include user name and password?

Or does anybody have an example persistence.xml for an Atlas cluster?


Hi @Marcus_Blumel and welcome to the MongoDB community forum!!

<property name="" value="27017"/>
<property name="" value="localhost"/>
<property name="" value="xrn-testing"/>

The localhost connection you advised was working may be due to the above configuration details (and possibly more). However, this appears to be more of a eclipselink question rather than a MongoDB question. The connection string provided is generally for the official MongoDB drivers, MongoDB Compass or mongosh.

You may wish to raise this in the Eclipse forum or possibly Stack Overflow to see if the software is capable of using the DNS Seed List Connection Format connection string example you provided.

However, to answer your questions:

In saying so, for the port specific question, I would refer to the following Connecting to a Database Deployment documentation which includes the port details for Atlas.

Based off your connection string, the value is most likely the SRV (not inclusive of the prefix). More details regarding the SRV record within DNS Seed List Connection Format can be detailed on the following topic reply.

Let us know if you have any further questions.

Best Regards