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 don't call ensureIndex
directly, you indicate that field should be indexed in your schema like this:
var schema = mongoose.Schema({
projectName : String,
authorName : { type: String, index: true }
});
Based on that definition, Mongoose will call ensureIndex
for you when you register the model via the mongoose.model
call.
To see the ensureIndex
calls that Mongoose is making, enable debug output by adding the following to your code:
mongoose.set('debug', true);