Skip to content

dropIndex by Name Affects All Collections Instead of Target Collection Only #246

Description

@tleonardi

When dropping an index by name from a specific collection, the operation incorrectly deletes the index from all collections in the database that have an index with the same name, instead of only affecting the target collection.

This can be reproduced by creating identical indexes on two different collections (e.g., collectionOne and collectionTwo both indexing myField). By default, both get the index name myField_1.

If you run collectionOne.dropIndex("myField_1"), the index is incorrectly deleted from collectionTwo as well. The expected behavior is that collectionTwo remains untouched.

The issue is in AbstractMongoDatabase.dropIndexes(). When handling an index name (String), the delete query sent to system.indexes filters only by name, completely omitting the namespace (ns). Consequently, it matches all indexes with that name globally.

A PR to fix the issue will follow shortly.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions