title: Save mongoose document again after deleting it
body: <p>I try to unit test my restify node.js-app using mocha and without mocking out the mongodb database. As some tests will alter the database, I'd like to reset its contents before each test.</p>
  
  <p>In my tests I also need to access the mongoose documents I am creating. Thus I have to define them outside of the <code>beforeEach</code> hook (see the <code>user</code> document below).</p>
  
  <p>However, it seems like it's not possible to save a document a second time after emptying the database.</p>
  
  <p>Below is a minimal example I've come up with. The second test will fail in that case, because <code>user</code> won't get saved a second time. If I delete the first test, <code>beforeEach</code> only gets called once and everything works nicely.
  Also if I define <code>user</code> inside the <code>beforeEach</code> hook, it works as well.</p>
  
  <p>So my actual question: Is it possible to work around this issue and save a document a second time after deleting it? Or do you have any other idea on how I can reset the database inside the <code>beforeEach</code> hook? What's the proper way to have the same database setup before each test case?</p>
  
  <pre><code>var mongoose = require('mongoose')
  var Schema = mongoose.Schema
  var should = require('should')
  var flow = require('async')
  
  var UserSchema = new Schema({
    username: {type: String, required: true, unique: true},
    password: {type: String, required: true},
    name: {type: String, default: ''}
  })
  
  mongoose.model('User', UserSchema)
  
  var User = mongoose.model('User')
  
  describe('test mocha', function() {
    var user = new User({
      username: 'max',
      password: 'asdf'
    })
  
    before(function(done) {
      var options = {server: {socketOptions: {keepAlive: 1}}}
      mongoose.connect('mongodb://localhost/unittest', options, done)
    })
  
    beforeEach(function(done) {
      flow.series([
        function(callback) {
          User.collection.remove(callback)
        }, function(callback) {
          user.save(callback)
        }
      ], function(err, res) {
        done()
      })
    })
  
    it('should pass', function(done) {
      true.should.equal(true)
      // also access some elements of user here
      done()
    })
  
    it('should have a user', function(done) {
      User.find().exec(function(err, res) {
        res.should.not.be.empty
      })
      done()
    })
  
    after(function(done) {
      mongoose.disconnect()
      done()
    })
  })
  </code></pre>