Mongoose Not Creating Indexes

Hook the 'index' event on the model to see if any errors are occurring when asynchronously creating the index:

User.on('index', function(err) {
    if (err) {
        console.error('User index error: %s', err);
    } else {
        console.info('User indexing complete');
    }
});

Also, enable Mongoose’s debug logging by calling:

mongoose.set('debug', true);

The debug logging will show you the ensureIndex call it’s making for you to create the index.

Leave a Comment