-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Hook to collection creation #7893
Comments
By default, Mongoose doesn't create collections automatically unless you enable We can add middleware for |
That would be helpful yes, thank you. Will it be possible to override the creation process or just add pre creation commands ? |
@abouroubi just add pre and post creation commands. Is that enough for your use case? |
We'd love to see a |
@FortesJos what's your use case for wanting a pre('createCollection') hook? |
The use case is preventing (accidental) creation of new collections. |
The problem is that, if you attempt to insert a document into a nonexistent collection, MongoDB will create the collection automatically. So there's no good way to prevent accidentally deleting a collection in all cases. Would that be a deal breaker for you? |
That is not an issue. We'll be using it to stop running the app initially. When inserting would be an issue later on, these can be caught via the usual hooks. |
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
I want to execute some custom commands on collection creation.
Is there a way to hook to or to override the automatic collection creation by mongoose ?
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
The text was updated successfully, but these errors were encountered: