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

syncIndex option to hide instead of drop index #14868

Closed
2 tasks done
vvandens opened this issue Sep 6, 2024 · 3 comments
Closed
2 tasks done

syncIndex option to hide instead of drop index #14868

vvandens opened this issue Sep 6, 2024 · 3 comments
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class
Milestone

Comments

@vvandens
Copy link

vvandens commented Sep 6, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

I love the syncIndex() feature that helps to have a single source of truth for our MondoDB schema indexing.

However, dropping an index is never 100% sure, especially on large MongoDB databases with large codebase querying the collections. There can be some rarely used piece of code that need once a time an index and thus will not update the $indexStats frequently enough to identify that this index is actually needed.

One recommandation from the MongoDB team is to hide an index before actually dropping it. It will exclude the index from the query planner options and whenever you identify a performance issue due to this exclusion, you can instantly make it visible again. This is way faster and less resource consuming than re-creating the index from scratch. The latter can last for hours on large collections and your system suffers during this re-creation.

It would be nice to pass an option to the syncIndex({hide: true}) to hide the indexes missing in the schema instead of dropping them immediately. Once the system has run for a certain period of time without problem, then we can call the syncIndex({hide:false}) to actually drop them.

Motivation

Secure the synchronization of the indexes and prevent mis-dropping of rarely used indexes with immediate rollback if necessary.

Example

model.syncIndex({hide: true}); // hide missing schema indexes instead of dropping them
model.syncIndex(); // actually drop missing schema indexes. Same as {hide:false}
@vvandens vvandens added enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class labels Sep 6, 2024
@vvandens
Copy link
Author

vvandens commented Sep 6, 2024

Just found out that there is no such hideIndex() method on the native MongoDB driver but here is a SO post that describes an elegant solution to mimic what mongosh does with hideIndex().

@vkarpov15 vkarpov15 added this to the 7.x Unprioritized milestone Sep 9, 2024
@vkarpov15
Copy link
Collaborator

We will consider this for a future release, this is a neat feature idea, but would be tricky for us to implement until the MongoDB Node driver supports hideIndex()

@vvandens
Copy link
Author

Thanks @vkarpov15 for considering this evolution.
Whenever you would like to anticipate the hideIndex() inclusion in MongoDB node driver, the following code snippet extracted from the SO post linked above works like a charm (with Mongoose connection and model):

connection.db.command({
  'collMod': model.collection.name,
  index: { name: indexName, hidden: true }
})

@vkarpov15 vkarpov15 modified the milestones: 7.x Unprioritized, 8.8 Sep 15, 2024
vkarpov15 added a commit that referenced this issue Oct 28, 2024
feat(model): add hideIndexes option to syncIndexes() and cleanIndexes()
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 new feature This change adds new functionality, like a new method or class
Projects
None yet
Development

No branches or pull requests

2 participants