Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mongoose.set('autoIndex', false) having no effect #8158

Closed
kiprobinson opened this issue Sep 12, 2019 · 0 comments
Closed

mongoose.set('autoIndex', false) having no effect #8158

kiprobinson opened this issue Sep 12, 2019 · 0 comments
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone

Comments

@kiprobinson
Copy link

kiprobinson commented Sep 12, 2019

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.
  • If the tests collection does already exist, no new indexes should be added automatically.
    • Actual: The indexes are added to tests collection automatically.

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 to true by default. You can change this default by setting mongoose.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().

@vkarpov15 vkarpov15 added this to the 5.7.2 milestone Sep 19, 2019
@vkarpov15 vkarpov15 added has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Sep 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Projects
None yet
Development

No branches or pull requests

2 participants