Skip to content

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

Closed
@kiprobinson

Description

@kiprobinson

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().

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new feature

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @vkarpov15@kiprobinson

        Issue actions

          `mongoose.set('autoIndex', false)` having no effect · Issue #8158 · Automattic/mongoose