Description
Do you want to request a feature or report a bug? I'm not sure. The documentation in one place says this should work. In another place, it does not mention it. If this is supposed to work, then I'd call this a bug. If it is not, then please update the documentation (or, ideally, implement this feature).
What is the current behavior?
mongoose.set('autoIndex', false);
has no effect.
If the current behavior is a bug, please provide the steps to reproduce.
Sample application:
const mongoose = require('mongoose');
mongoose.set('autoIndex', false);
const testSchema = new mongoose.Schema({
field1: {type: String, index: true},
field2: {type: String, index: false},
field3: {type: String, unique: true},
});
const testModel = mongoose.model('Test', testSchema);
mongoose.connect(`mongodb://localhost:27017/testdb`).then(() =>
console.log(`Successfully connected to MongoDB server`)
).catch((err) => {
console.error(err);
});
What is the expected behavior?
- If the
tests
collection does not already exist, it should not be created automatically.- Actual: The
tests
collection is created automatically.
- Actual: The
- If the
tests
collection does already exist, no new indexes should be added automatically.- Actual: The indexes are added to
tests
collection automatically.
- Actual: The indexes are added to
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
- Node: 10.16.0
- Mongoose: 5.7.0
- MongoDB Server: 4.2.0 Community
- MongoDB NPM package: 3.3.2
Additional Information
According to the documentation for autoIndex
:
The
autoIndex
option is set totrue
by default. You can change this default by settingmongoose.set('autoIndex', false);
However, the documentation for mongoose.set()
doesn't mention autoIndex
as a supported setting
Also, in the "Indexes" section of the guide, it lists four ways of setting the property, but none are mongoose.set()
.
Activity