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

Remove Mongoose buffering layer #8702

Closed
vkarpov15 opened this issue Mar 21, 2020 · 4 comments
Closed

Remove Mongoose buffering layer #8702

vkarpov15 opened this issue Mar 21, 2020 · 4 comments

Comments

@vkarpov15
Copy link
Collaborator

vkarpov15 commented Mar 21, 2020

Shouldn't be necessary if useUnifiedTopology is turned on by default. You can still do Model.find() before calling mongoose.connect().

Should fix issues:

#3698
#4979

@AbdelrahmanHafez
Copy link
Collaborator

I am not quite sure what useUnifiedTopology achieves, it feels like a mystery to me.

Is that a native solution for buffering on the native mongodb driver?
Can we expect the same behavior of "initialize models, and run commands, and connect later" by useUnifiedTopology?

I liked the buffering behavior mainly because I didn't have to wait until the database is connected to initialize the rest of my code.

@vkarpov15
Copy link
Collaborator Author

Yes that is essentially the idea. With useUnifiedTopology, when you send an operation like Model.find(), the MongoDB driver will try to find a server to send the operation to for serverSelectionTimeoutMS milliseconds. If it can't for some reason, like if you haven't called connect() or the server is down for longer than serverSelectionTimeoutMS, then the operation errors out.

@AbdelrahmanHafez
Copy link
Collaborator

Thank you for the explanation, nice to see that behavior being achieved natively.

@vkarpov15
Copy link
Collaborator Author

We took a closer look at this and it looks like we're going to have to keep buffering, at least partially. The problem is that Mongoose buffering allows you to create models and execute commands before calling connect(), which is something the MongoDB driver doesn't allow, even with the PR in ☝️ .

However, keeping this behavior isn't terrible, because the behavior we actually want to get rid of is buffering after initial connection. Mongoose buffering can kick in with cases where Mongoose thinks it is disconnected from the database, which is a problem for cases like #9262 where we may want to still allow queries when Mongoose thinks it is disconnected. This is also a problem because now Mongoose needs to maintain its own separate logic for when operations should be buffered, which may not line up exactly with how the MongoDB driver's server selection loop handles "buffering".

TLDR; we're going to make a much more minor backwards breaking change that prevents Mongoose from buffering after initial connection, but we'll keep pre-connection buffering as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants