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

Make autoCreate true by default #8814

Closed
vkarpov15 opened this issue Apr 18, 2020 · 7 comments
Closed

Make autoCreate true by default #8814

vkarpov15 opened this issue Apr 18, 2020 · 7 comments
Labels
backwards-breaking developer-experience This issue improves error messages, debugging, or reporting
Milestone

Comments

@vkarpov15
Copy link
Collaborator

Change streams and transactions don't work unless the collection already exists, so it would be helpful if autoCreate was automatically set so you could just call Model.init().

@vkarpov15 vkarpov15 added backwards-breaking developer-experience This issue improves error messages, debugging, or reporting labels Apr 18, 2020
@vkarpov15 vkarpov15 added this to the 6.0 milestone Apr 18, 2020
@deser
Copy link

deser commented Jan 14, 2021

In documentation there is note that autoCreate is not supposed for production. Why it is written so? With mongoose 6 it will be ok for production?

@vkarpov15
Copy link
Collaborator Author

That's a good point. The reason why we're considering this change is for consistency with autoIndex: autoIndex is true by default, and we recommend turning that option off in prod as well. Worth thinking more about whether we optimize defaults for ease of development or ease of running in prod.

@deser
Copy link

deser commented Jan 16, 2021

But what should I do then when I can have some absent collections which might be created within transactions in prod ( I have 4.2)? Isn't autoCreate is the only option we have here besides calling createCollection manually (which is what autoCreate eventually does)?

@vkarpov15
Copy link
Collaborator Author

You would have to call createCollection(). However, it is unlikely that you would have to automatically create collections in prod, which is why we don't recommend autoCreate for prod: in most applications it is an extra round trip to the database when the app starts up that typically doesn't do anything, because in most cases the collection already exists.

@deser
Copy link

deser commented Jan 20, 2021

I think if this is the only reason you don't recommend to have autoCreate turned on in prod then it might be incorrect. On my project I am pretty ok about these roundtrips and I don't want to implement autoCreate by myself to not create mistakes in code. I must be sure that all collections create for transactions to not fail.

@vkarpov15
Copy link
Collaborator Author

In that case I think you're fine to enable autoCreate in prod.

@deser
Copy link

deser commented Jan 25, 2021

So documentation should mirror that case then and be not so strict on not using autoCreate in prod :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backwards-breaking developer-experience This issue improves error messages, debugging, or reporting
Projects
None yet
Development

No branches or pull requests

2 participants