title: A Spring boot + mongo Heroku deployment fails due to error creating the mongoTemplate bean
body: <p>I have a jhipster-generated Spring Boot + mongo project that deploys locally with success, but deploying to Heroku with the ObjectRocket add-on is failing with this error:</p>
  <pre><code>[org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; 
  nested exception is org.springframework.dao.DataAccessResourceFailureException: Timed out after 30000 ms while waiting for a server that matches 
  com.mongodb.client.internal.MongoClientDelegate$1@4339e0de. Client view of cluster state is {type=REPLICA_SET, servers=[];
  nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@4339e0de.
  Client view of cluster state is {type=REPLICA_SET, servers=[]
  </code></pre>
  <p>I believe that my config vars with my <code>MONGODB_URI</code> variable are correct because in a shell, I have connected to my mongo database with the same connection string from my config vars with success. This connection string, stored in <code>MONGODB_URI</code>, has the form <code>mongodb://&lt;USERNAME&gt;:&lt;PASSWORD@&lt;host1&gt;:&lt;port1&gt;,&lt;host2&gt;:&lt;port2&gt;,&lt;host3&gt;:&lt;port3&gt;/&lt;DATABASE_NAME&gt;?replicaSet=&lt;replicaSetID&gt;</code>. This also means I have already set up my mongodb dbname, user, and password on the ObjectRocket side.</p>
  <p>My procfile has the line <code>--spring.data.mongodb.database=$(echo &quot;$MONGODB_URI&quot; | sed &quot;s/^.*:[0-9]*\///g&quot;)</code> referencing <code>MONGODB_URI</code>. My <code>application-prod.yml</code> config file has the entry:</p>
  <pre><code>spring:
    data:
      mongodb:
        uri: ${MONGODB_URI}?authMode=scram-sha1
  </code></pre>
  <p>Yet I am not succeeding with deployment because of the failed connection to my mongo database instance. Any help would be appreciated.</p>
  <p>The error with more context from the stacktrace at this pastebin paste: <a href="https://pastebin.com/wNd3TxUL" rel="nofollow noreferrer">https://pastebin.com/wNd3TxUL</a></p>