title: MongoError: No transaction started
body: <p>I am using mongoose transactions for the first time. Following the documentation and some articles, I was able to get it running using <strong>run-rs</strong> for local replicas. However, I encountered two issues,</p>
  <ol>
  <li>Even though the transaction reflects on the replica sets, mongoose always throws the error <strong>MongoError: No transaction started</strong>. I have tried checking for solutions but can't find any to solve this problem.</li>
  <li>Upon successful completion of the transaction, there's another async function that is meant to send notification emails. However, I realized that somehow, this <em>notification email function</em> runs before the transaction occurs, then the <em>transaction function</em> runs second. I am guessing this might have to do with promises, correct me if I am wrong.</li>
  </ol>
  <p>Here's what the two functions look like.</p>
  <pre><code>await transactionDb
         .handleMoneyTransfer({
              senderId,
              receiverId: paymentInfo.getReceiver(),
              amount: paymentInfo.getAmountToPay(),
              ref
            })
  </code></pre>
  <pre><code>return await sendNotificationEmail({ ref, user })
  </code></pre>
  <p>The <code>handleMoneyTransfer</code> function is meant to run first, then the <code>sendNotificationEmail</code> is meant to run next, but that's not the case here.</p>
  <p>Here is the code that handles the mongoose transaction listed below.</p>
  <pre><code>async function handleMoneyTransfer({ senderId, receiverId, amount, ref }) {
      const session = await mongoose.startSession()
      try {
        const sender = await User.findOne({ _id: senderId }).session(session)
        sender.balance -= amount
        await sender.save({ session })
        const receiver = await User.findOne({ _id: receiverId }).session(session)
        // receiver.balance += amount
        const transactionInfo = await Transaction.findOne({
          reference: ref
        }).session(session)
        const newEscrow = await new Escrow({
          amount,
          reference: ref,
          buyerInfo: {
            buyerId: sender._id,
            email: sender.email
          },
          sellerInfo: {
            sellerId: receiverId,
            email: receiver.email
          },
          currentTransaction: {
            transaction: transactionInfo
          }
        })
        await newEscrow.save({ session })
        await session.commitTransaction()
      } catch (error) {
        await session.abortTransaction()
      } finally {
        session.endSession()
      }
    }
  </code></pre>
  <p>Here is how I connect using mongoose</p>
  <pre><code>const setupDB = async (uri, dbUrl) =&gt; {
    try {
      await mongoose.connect(`${uri}/${dbUrl}`, {
        useUnifiedTopology: true,
        useNewUrlParser: true,
        replicaSet: 'rs'
      })
      console.log('Connected')
    } catch (e) {
      return console.log(e)
    }
  }
  </code></pre>
  <p>which is translated to this</p>
  <pre><code>setupDB(
    'mongodb://DESKTOP-SNA1HQK:27017,DESKTOP-SNA1HQK:27018,DESKTOP-SNA1HQK:27019',
    'escrow?replicaSet=rs'
  )
  </code></pre>
  <p>Now, I am stuck on fixing the <code>No transaction started </code> error and also getting these functions to run in the order they are placed.</p>
  <p><strong>Help will be very much appreciated, thank you in advance.</strong></p>