Automattic / mongoose

MongoDB object modeling designed to work in an asynchronous environment.
https://mongoosejs.com
MIT License
26.94k stars 3.84k forks source link

Remove `skipInit` parameter for `model()` #4625

Closed clocked0ne closed 3 years ago

clocked0ne commented 8 years ago

http://mongoosejs.com/docs/api.html

Mongoose#model(name, [schema], [collection], [skipInit])

Defines a model or retrieves it. Parameters:

name model name [schema] [collection] name (optional, induced from model name) [skipInit] whether to skip initialization (defaults to false)

Nowhere in the docs is the purpose of skipInit explained properly.

What is the purpose of skipping Initialization? What are the use cases and why does it default to false? Is it an optimisation flag? Does it avoid setting schema defaults? This seems like a big oversight to me.

I asked this same question in the Google Group and no one replied in 4 months... this should really be documented properly.

vkarpov15 commented 8 years ago

To be honest this option does next to nothing. It likely did something in back in 2012 but right now all it does is skip emitting the init event on a model. Will get rid of it in the next backwards breaking release.

joe-fenton commented 6 years ago

I've found that if I set skipInit = true when testing with Jest, it doesn't complain when it has finished the unit tests, that there is an open promise. So when I have a node environment variable set to 'test', skipInit is true and there are no complaints. I don't know what it does behind the scenes. I had the recommendation from a stackoverflow question on the subject. I agree, more documentation on the issue would be nice, as I'm not sure if setting to true is causing another problem.

vkarpov15 commented 6 years ago

@joe-fenton can you provide me with some example code that demonstrates what you're seeing re: Jest warning about an open promise?