title: Bulk loading MongoDB database from Java/Groovy for testing
body: <p>I've got an existing Grails/MongoDB application that I am adding some automated tests to.  I want those tests to be executed against a specific set of data in a Mongo collection.  I want the tests to be able to mangle the data (with predictable results, if I'm lucky) and then be able to quickly drop and recreate/reload the database so that I can run the test again.</p>
  
  <p>Since I'm going to base this seed test data on real data from our production system, I'd like to be able to perhaps load the data from a JSON/BSON format that I could retrieve from a query in the Mongo shell or something similar.</p>
  
  <p>Basically I don't want to have to write a hundred lines of code like the following:
      new Record(name: 'John Doe', age: '25', favoriteColor: 'blue').save()</p>
  
  <p>Except with 30 properties each, all the while ensuring that constraints are met and that the data is realistic.  That's why I want to use production data.</p>
  
  <p>I also don't want to have to resort to spawning execs that run mongorestore to load and reload real data, since that would require additional software to be running on the tester's machine.</p>
  
  <p>Is there a better way?  Perhaps somehow unmarshalling raw JSON into something that I can then execute with the Grails MongoDB GORM or GMongo or a direct call to the Java MongoDB driver?</p>