title: What is a TransientTransactionError in Mongoose (or MongoDB)?
body: <p>I have <code>server.js</code> and <code>db.js</code> The <code>db.js</code> file interacts with my database using Mongoose and I use <code>server.js</code> to call functions from <code>db.js</code> :</p>
  
  <pre><code>var mongoose = require('mongoose');
  mongoose.connect('', { useNewUrlParser: true })
  var Schema = mongoose.Schema;
  
  module.exports = function () {
      var db = mongoose.connection;
      db.on('error', console.error.bind(console, 'connection error:'));
      return db.once('open', function() {
          console.log("Connected to DB")
          var postschema = new Schema({
              title: String,
              intro: String,
              body: String,
              author: String,
              timestamp: { type: Date, default: Date.now }
          });
  
          var post = mongoose.model('post', postschema);
  
          return {
              newPost(title, intro, body, author) {
                  var newpost = new post({
                      title: title,
                      intro: intro,
                      body: body,
                      author: author
                  })
              },
              getPostsAll() {
                  post.find({}, function (err, res) {
                      return (`Error:${err} Posts:${res}`)
                  })
              }
          }
      })
  }
  </code></pre>
  
  <p>And my server.js calls three functions from <code>db.js</code> :</p>
  
  <pre><code>var DB = require('./db.js')
  var db = DB()
  db.getPostsAll()
  db.newPost()
  </code></pre>
  
  <p>I don't understand why I get this error :</p>
  
  <pre><code>connection error: { MongoNetworkError: connection 4 to black-test-shard-00-01-ewyaf.mongodb.net:27017 closed
  at TLSSocket.&lt;anonymous&gt; (E:\HTML\black-box\node_modules\mongodb-core\lib\connection\connection.js:276:9)
  at Object.onceWrapper (events.js:272:13)
  at TLSSocket.emit (events.js:185:15)
  at _handle.close (net.js:541:12)
  at TCP.done [as _onclose] (_tls_wrap.js:379:7)
    name: 'MongoNetworkError',
    errorLabels: [ 'TransientTransactionError' ],
    [Symbol(mongoErrorContextSymbol)]: {} }
  </code></pre>
  
  <p>What am I doing wrong? I found <a href="https://docs.mongodb.com/manual/core/transactions/#retry-transaction" rel="noreferrer">an article</a> but can't make anything of it.</p>