I would like to call ensureIndex
on the authorName
, what is the command and where in this code should I put it?
var mongoose = require(
You could use this statement:
mongoose.connection.collections['my_collection'].ensureIndex({ "key": 1 }, { "unique": true }, callback);
For example you want to do some integration tests, so you will need to drop your collections rapidly.
In that case mongoose doesn't setup indexes again during runtime even if option autoIndex
is set to true
.
This answer could be useful in that case.