title: MongoDb ConnectionURL in jdoconfig.xml
body: <p>I have setup a MongoDB instance on AWS and am trying to connect to it from another AWS instance where my web app is installed.</p>
  
  <p>The following is the contents of my jdoconfig.xml file:</p>
  
  <pre><code>&lt;jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig http://java.sun.com/xml/ns/jdo/jdoconfig_3_0.xsd"&gt;
  
      &lt;persistence-manager-factory name="MY-PMF"&gt;
          &lt;property name="javax.jdo.PersistenceManagerFactoryClass"
              value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" /&gt;
          &lt;property name="javax.jdo.option.ConnectionURL" value="mongodb://ec2-[...].eu-west-1.compute.amazonaws.com:27017/mydb" /&gt;
          &lt;property name="javax.jdo.option.Mapping" value="mongodb" /&gt;
          &lt;property name="javax.jdo.option.ConnectionUserName" value="myuser" /&gt;
          &lt;property name="javax.jdo.option.ConnectionPassword" value="mypassword" /&gt;
          &lt;property name="javax.jdo.option.Optimistic" value="false" /&gt;
          &lt;property name="datanucleus.autoCreateSchema" value="true" /&gt;
      &lt;/persistence-manager-factory&gt;
  &lt;/jdoconfig&gt;
  </code></pre>
  
  <p>However, the web app cannot connect to the MongoDB instance.  The following are error messages from the logs:</p>
  
  <pre><code>com.mongodb.MongoException$Network: can't call something : localhost/127.0.0.1:27017//ec2-[...].eu-west-1.compute.amazonaws.com:27017/mydb
      at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:226)
      at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:313)
      at com.mongodb.DB.command(DB.java:174)
      at com.mongodb.DB.command(DB.java:158)
      at com.mongodb.DB.command(DB.java:198)
      at com.mongodb.DB.command(DB.java:144)
      at com.mongodb.DB._doauth(DB.java:555)
      at com.mongodb.DB.authenticate(DB.java:492)
      at org.datanucleus.store.mongodb.ConnectionFactoryImpl$ManagedConnectionImpl.getConnection(ConnectionFactoryImpl.java:200)
      at org.datanucleus.store.mongodb.MongoDBStoreManager.addClasses(MongoDBStoreManager.java:127)
      at org.datanucleus.store.AbstractStoreManager.addClass(AbstractStoreManager.java:1137)
      at org.datanucleus.ObjectManagerImpl.newObjectId(ObjectManagerImpl.java:3310)
      at org.datanucleus.api.jdo.JDOPersistenceManager.newObjectIdInstance(JDOPersistenceManager.java:1627)
      at org.datanucleus.api.jdo.JDOPersistenceManager.getObjectById(JDOPersistenceManager.java:1749)
      at com.myapp.server.auth.MyActionHandler.execute(MyActionHandler.java:67)
      at com.myapp.server.auth.MyActionHandler.execute(MyActionHandler.java:1)
      at com.gwtplatform.dispatch.server.AbstractDispatchImpl.doExecute(AbstractDispatchImpl.java:153)
      at com.gwtplatform.dispatch.server.AbstractDispatchImpl.execute(AbstractDispatchImpl.java:111)
      at com.gwtplatform.dispatch.server.AbstractDispatchServiceImpl.execute(AbstractDispatchServiceImpl.java:80)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:616)
      at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
      at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
      at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
      at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:263)
      at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:178)
      at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
      at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:62)
      at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:168)
      at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
      at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:168)
      at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
      at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118)
      at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:680)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:679)
  Caused by: java.io.IOException: couldn't connect to [localhost/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused
      at com.mongodb.DBPort._open(DBPort.java:222)
      at com.mongodb.DBPort.go(DBPort.java:111)
      at com.mongodb.DBPort.call(DBPort.java:78)
      at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:217)
      ... 55 more
  </code></pre>
  
  <p>It looks like the ConnectionURL is not correct; DataNucleus JDO implementation is trying to connect to localhost instead of the instance where my DB is located.</p>
  
  <p><strong>Can anyone show me what the correct ConnectionURL should look like or if you think the problem is elsewhere point me to it?</strong></p>