title: Mongoose & unique field
body: <p>I have the following schema with mongoose:</p>
  
  <pre><code>var SimSchema = new Schema({
      msisdn     : { type : String , unique : true, required : true },
      imsi       : { type : String , unique : true, required : true },
      status     : { type : Boolean, default: true},
      signal     : { type : Number },
      probe_name : { type:  String , required : true }
  });
  </code></pre>
  
  <p>I have <code>unique</code>option for the <code>msisdn</code> and <code>imsi</code>.</p>
  
  <p>In some cases this condition is well respected. 
  For the following <code>mocha</code> test:</p>
  
  <pre><code>"use strict";
  
  var app      = require('../../app');
  var http     = require('http');
  var request  = require('supertest');
  var mongoose = require('mongoose');
  var should   = require('should');
  
  
  
  describe('[ Sim controller ] ', function(){
    before(function(done) {
      app.set_env('test');
      this.server = app.start(function() {
        mongoose.connection.db.dropDatabase(function() {
          done();
        })
      });
    });
  
  
    beforeEach(function(done){
      done();
    });
  
  
    it('Sim with good parameters should be created in the database', function(done){
      var newSim = {
        msisdn:     '1234',
        imsi:       '007',
        probe_name: 'BOUCHON_1'
      };
  
      request(this.server)
        .post('/sims')
        .set('Content-Type', 'application/json')
        .send(newSim)
        .expect(200).end(function(err, res) {
          if (err) return done(err);
          res.body.should.have.property('imsi');
          res.body.should.have.property('probe_name');
          res.body.should.have.property('msisdn');
          setTimeout(function() {
            done();
          }, 1000);
        });
    });
  
  
    it('Sim imsi/msisdn is unique in the database', function(done){
      var newSim = {
        msisdn:     '1234',
        imsi:       '007',
        probe_name: 'BOUCHON_1'
      };
  
      request(this.server)
        .post('/sims')
        .set('Content-Type', 'application/json')
        .send(newSim)
        .expect(200).end(function(err, res) {
          if (err) return done(err);
          res.body.should.have.property('error').equal('Duplicate Item');
          done();
        });
    });
  
  
    after(function(done) {
      app.stop(done);
    });
  });
  </code></pre>
  
  <p>It's working fine if I run it directly: </p>
  
  <pre><code>julio$ mocha test/controllers/ctrl_sim.js 
  </code></pre>
  
  <p>But If I run it thanks to the recessive option it failed:</p>
  
  <pre><code>  1) [ Sim controller ]  Sim imsi/msisdn is unique in the database:
       Uncaught AssertionError: expected { __v: 0,
    imsi: '007',
    msisdn: '1234',
    probe_name: 'BOUCHON_1',
    _id: '530a2b7f52273aa90783baf0',
    status: true } to have property 'error'
  </code></pre>
  
  <p>I read on stack that sometimes the <code>unique</code> condition is not well respected as the index is not refreshed.
  Do you think this is my case? In fact, I delete the database for each mocha test suite. Maybe mongo doesn't have the time to recreate all the indexes each time.</p>
  
  <p>Any idea?</p>