Skip to content

Instantly share code, notes, and snippets.

@gistfrojd
Created November 20, 2014 13:49
Show Gist options
  • Save gistfrojd/193e640b0bf74db5020f to your computer and use it in GitHub Desktop.
Save gistfrojd/193e640b0bf74db5020f to your computer and use it in GitHub Desktop.
mongoose mocha ensureIndex
// Mongoose.js and mocha/should testing with unique index constraints
// Use this snippet in your test, change the values to match your indexes
beforeEach(function(done) {
mongoose.connection.models.YourModelNameHere.collection.ensureIndex(
{
fieldWithConstraint: 1,
anotherFieldWithConstraint: 1
},
{
unique: true
}, function(err, data) {
done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment