title: Adding rollback ability with mongoose
body: <p>I have two collections, as follows:  </p>
  
  <pre><code>let User = Schema({
      logID: { type: String, required: true },
      name: { type: String, required: true }
  });
  let Log = Schema({
    id: { type: String, required: true },
    users: [{ type: Schema.Types.ObjectId, ref: 'User' }]
  });
  </code></pre>
  
  <p>I am performing the following transactions:  </p>
  
  <pre><code>let currLog = await Log.findOne({"id": logID});
  if(!currLog) throw new Error("No such log is there");
  let newUser = await User.save(payload);
  let updatedLog = await currLog.users.push(newUser._id);
  currLog.update();
  </code></pre>
  
  <p>So, if for some reason, LOG is not updated, The new user should be rolledback, as in deleted. 
  How can this be achieved exactly using mongoose?<br>
  I have looked in to the following resources:<br>
  <a href="https://docs.mongodb.com/manual/tutorial/perform-two-phase-commits/" rel="nofollow noreferrer">https://docs.mongodb.com/manual/tutorial/perform-two-phase-commits/</a><br>
  <a href="https://github.com/anand-io/mongoose-transaction" rel="nofollow noreferrer">https://github.com/anand-io/mongoose-transaction</a><br>
  But finding it difficult to implement the functionality.<br>
  Since, in my case, the data from the first transaction is being used in the second one (<strong>newUser._id</strong>).</p>