Answer the question
In order to leave comments, you need to log in
Why doesn't mongoose call createIndex?
I don't understand why mongoose doesn't call createIndex on the new model. In a collection in the mongo shell, the indexes specified in the model schema are not displayed (because they are not created); there is only one index on the _id field.
I deleted the collection in the moongo shell more than once and tried to check again, but all in vain. I also tried to remove useCreateIndex in the mongoose config, but it doesn’t even give me a deprecation warning, like ensureIndex is deprecated, use createIndex instead.
In the mongo shell, the index is quietly created via createIndex, but that's not the point. Sense then from the mongoose scheme ..
Options when connecting to the mongoose:
{
"useNewUrlParser": true,
"useFindAndModify": false,
"useCreateIndex": true,
"useUnifiedTopology": true
}
const { Schema, model } = require('mongoose');
const schema = new Schema({
telegramId: { type: Number, required: true, unique: true }
});
module.exports = model('User', schema);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question