title: Symfony2 Doctrine MongoDB rollback
body: <p>I am trying to build a secure of set of tests with Symfony2, Doctrine and MongoDB.</p>
  
  <p>What I need to do is to load a lot of fixtures when a test begin, and unload them once it ends. I thought of doing it with a <strong>transaction</strong>, but... I couldn't find documentation on how to do it with Doctrine and Mongo!</p>
  
  <p>I found <a href="http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/transactions-and-concurrency.html#approach-2-explicitly" rel="nofollow">good documentation</a> in the Doctrine docs regarding how to do transactions with the ORM, but not regarding the ODM.</p>
  
  <p>So I took a look at the <a href="https://github.com/doctrine/mongodb/blob/master/lib/Doctrine/MongoDB/Connection.php" rel="nofollow">source code of the <code>Connection.php</code></a> class used by Doctrine-Mongo too and I haven't found the <code>beginTransaction</code>, <code>commit</code>and <code>rollback</code> methods that the <a href="https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Connection.php" rel="nofollow">dbal version</a> uses.</p>
  
  <p>I was clueless, then I asked myself "Is it even possible to rollback in MongoDB?", and the answer if found in the <a href="http://www.mongodb.org/display/DOCS/Developer+FAQ#DeveloperFAQ-HowdoIdotransactions/locking?" rel="nofollow">MongoDB FAQ</a> was:</p>
  
  <blockquote>
    <p>MongoDB does not use traditional locking or complex transactions with rollback</p>
  </blockquote>
  
  <p>:( So I guess that's why there is no <code>beginTransaction</code> or whatsoever in the ODM...</p>
  
  <p>But my problem remains: <strong>how can I implement a sort of rollback for my tests?</strong></p>
  
  <p>The only idea I got right now is to manually get all the ids of the Document I load and then remove them in the <code>tearDown()</code>. But, well... it kinda sucks, doesn't it?</p>
  
  <p>Other ideas??</p>
  
  <p><strong>EDIT:</strong>
  After my first comment to this question, regarding the fact that I want to have the same DB in test and development, I thought: <strong><em>why don't use a separate test database, where the development database gets copied when the tests start, and that can be light-heartedly dropped?</em></strong></p>
  
  <p>Could it be a better idea? It actually looks easier and more secure to me. What do you guys think?</p>
  
  <p>Thanks :)</p>