title: Mongoose createConnection and Document.prototype.save()
body: <p>I am building a multi tenant app with only a few connections (max 3 or 4) on the same mongo host. What I am really doing is establishing mongoose connections at server startup and store it in a context object.</p>
  <pre><code>// For each tenants
  tenantConnection(name, uri) =&gt; new Promise((resolve, reject) =&gt; {
      const connection = mongoose.createConnection(uri, {
        useCreateIndex: true,
        useNewUrlParser: true,
        useFindAndModify: false,
        retryWrites: false,
        useUnifiedTopology: true
      })
      connection.on('connected', async () =&gt; {
        const MessageModel = connection.model('Message', Message) // &lt;- Message is a classic mongoose Schema
        ...
        return resolve({ connection, models: { Message: MessageModel } })
      })
    })
  </code></pre>
  <p>All works well except when I am trying to use the prototype <code>.save()</code> (same with <code>Model.create({...})</code>. When I try to create a new record, the function stuck, no callback are triggered nor any error.</p>
  <pre><code>const { models: { Message } } = tenant
  const messageRecord = new Message({ content }
  await messageRecord.save() // -&gt; Stuck here, nothing happens
  </code></pre>
  <p>At this moment, the only way I have found is to use <code>UpdateOne({}, {...}, {upsert: true})</code> to create records but I'd rather like to use native mongoose prototype <code>.save()</code> to trigger the setters from my schema.</p>
  <p>Does anyone has any idea of what I am doing wrong ?</p>