-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
testscollection does not already exist, it should not be created automatically.- Actual: The
testscollection is created automatically.
- Actual: The
- If the
testscollection does already exist, no new indexes should be added automatically.- Actual: The indexes are added to
testscollection 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
autoIndexoption is set totrueby 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().