-
-
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
connection event open is not equivalent to connected #10886
Comments
const mongoose = require('mongoose');
async function test() {
await mongoose.connect('mongodb://localhost:27017/', {useNewUrlParser: true,
useUnifiedTopology: true,});
await mongoose.connection.dropDatabase();
}
mongoose.connection.on('open', () => {
console.log('open fire');
});
mongoose.connection.on('connected', () => {
console.log('connected successfully');
});
test(); |
If there is a slight difference, I think we should mention that in the docs. |
from the source code is can see there are some differences @event @event https://github.com/Automattic/mongoose/blob/master/lib/connection.js#L642 Also in the code I can see the reconnect event is triggered differently for replica sets. |
its either a bug or bad documentation.
mongoose.connection emitted
connected
but neveropen
.as per docs
open: Equivalent to connected
I used in my app
connected
event as a ready signal to make sure my app was ready to receive traffic.what ended up happening is that the app was receiving traffic it was not able to service.
the
open
event was never emitted and I think that is the one needed for mongoose to operate properly?Looking at the source code,
open
andconnected
are not exactly identical. It would be nice to note the difference even if they are subtle.The text was updated successfully, but these errors were encountered: