Event listener is not working while calling createConnection
#11545
Labels
help
This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Do you want to request a feature or report a bug? BUG
What is the current behavior?
In current version of package, connection is not able to emit any event while calling
createConnection
mongoose function. This is happening because ofasPromise
that returns successful connection instance. Prior to version 6 it was working out of the box. I was able to listen on allconnectionStates
.I'm not able to listen event
createConnection
as mentioned here: https://github.com/Automattic/mongoose/blob/master/lib/index.js#L283If the current behavior is a bug, please provide the steps to reproduce.
npm init -y
)npm install --save mongoose
index.js
file and copy the below code and save that file.What is the expected behavior?
In an ideal scenario, it should print above statements based on the connectionState.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js Version: 16.13.2
Mongoose Version: 6.2.7
MongoDB Server Version: 5.0.6
Other comments
There is a workaround I can think of:
The above code prints based on the state. I'm not sure if this is an intended feature or a bug. In my opinion it is a bug since we are not able to emit events.
The text was updated successfully, but these errors were encountered: