title: Nestjs: How to use mongoose to start a session for transaction?
body: <p>The mongoose documentation to use a transaction is straightforward but when it is followed in nestjs, it returns an error:</p>
  <pre><code>Connection 0 was disconnected when calling `startSession`
  MongooseError: Connection 0 was disconnected when calling `startSession`
      at NativeConnection.startSession
  </code></pre>
  <p>My code:</p>
  <pre><code>const transactionSession = await mongoose.startSession();
      transactionSession.startTransaction();
  
      try
      {
        const newSignupBody: CreateUserDto = {password: hashedPassword, email, username};
    
        const user: User = await this.userService.create(newSignupBody);
  
        //save the profile.
        const profile: Profile = await this.profileService.create(user['Id'], signupDto);
  
        const result:AuthResponseDto = this.getAuthUserResponse(user, profile);
  
        transactionSession.commitTransaction();
        return result;
      }
      catch(err)
      {
        transactionSession.abortTransaction();
      }
      finally
      {
        transactionSession.endSession();
      }
  </code></pre>