title: Multi document transaction in MongoDB - Book & Author example
body: <p>I am new to MongoDB and as a learning exercise I am developing a Library Management System using Java in MongoDB. The problem I have encountered is, how to ensure Transaction properties in the following scenario :</p>
  
  <p>I have a Book class and an Author class, which have many-to-many relationship. Now when I am saving a specific book, it may have multiple authors. I am saving/updating the Authors first including a generated Book ID, then I am saving the Book class with the Author ID(s). Now, how can I ensure this multi-document save follows transaction properties?</p>
  
  <p>Searching through previous posts I got a <a href="http://docs.mongodb.org/manual/tutorial/perform-two-phase-commits/" rel="nofollow" title="Two phase commit">Two Phase Commit plan</a> as given in MongoDB website, but it is unclear to me how I could use that method in my application.</p>
  
  <p>Untill now, I have made "rollback" and "commit" alternative by shadow backup of documents, but in the long run this is not feasible as it doubles the database size. Also, I would like to know why MongoDB doesn't have an in-built method to handle transactions.</p>