title: TransientTransactionError while starting mongodb
body: <p>I am not able to solve the mongodb connection problem. I am getting the error below on starting node app.</p>
  
  <p>Here is my mongoose connection code.</p>
  
  <pre><code>var mongoose = require('mongoose');
  
  mongoose.Promise = global.Promise;
  mongoose.connect(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/ml').then(
      () =&gt; { console.log('Connected to mongodb!') },
      err =&gt; { console.log('Failed to connect to mongodb'); console.log(err); }
  );
  
  module.exports = {mongoose};
  </code></pre>
  
  <p>Here is the error.</p>
  
  <pre class="lang-none prettyprint-override"><code>Started up at port 80
  Failed to connect to mongodb
  { MongoNetworkError: failed to connect to server [10.160.0.2:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 10.160.0.2:27017]
      at Pool.&lt;anonymous&gt; (/home/shivamsharma_btp2/mlsever/magguland/node_modules/mongodb-core/lib/topologies/server.js:564:11)
      at Pool.emit (events.js:189:13)
      at Connection.&lt;anonymous&gt; (/home/shivamsharma_btp2/mlsever/magguland/node_modules/mongodb-core/lib/connection/pool.js:317:12)
      at Object.onceWrapper (events.js:277:13)
      at Connection.emit (events.js:189:13)
      at Socket.&lt;anonymous&gt; (/home/shivamsharma_btp2/mlsever/magguland/node_modules/mongodb-core/lib/connection/connection.js:246:50)
      at Object.onceWrapper (events.js:277:13)
      at Socket.emit (events.js:189:13)
      at emitErrorNT (internal/streams/destroy.js:82:8)
      at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
      at process._tickCallback (internal/process/next_tick.js:63:19)
    name: 'MongoNetworkError',
    errorLabels: [ 'TransientTransactionError' ],
    [Symbol(mongoErrorContextSymbol)]: {} }
  </code></pre>
  
  <p>Here are firewall rules of my google cloud app.</p>
  
  <p><img src="https://i.imgur.com/EkleNJR.png" alt=""></p>