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

Auto connect mongodb documentation #448

Closed
hnviradiya opened this issue Dec 25, 2021 · 3 comments
Closed

Auto connect mongodb documentation #448

hnviradiya opened this issue Dec 25, 2021 · 3 comments
Labels

Comments

@hnviradiya
Copy link

  • I'm submitting a question about how to use this project

  • I am connecting to mongodb during main startup of the project. But as initially mongodb is not available it throws below error. How do I make it retry in case of mongodb is not available. I tried posting on stackoverflow and also tried checking for developers at work portals but seems none of them are able to fix this.

  • I am unable to find any documentation for the same anywhere.

https://stackoverflow.com/questions/70410326/connect-mongo-auto-reconnect

(node:33) UnhandledPromiseRejectionWarning: MongoServerSelectionError: getaddrinfo EAI_AGAIN example-mongodb-svc
at Timeout._onTimeout (/usr/src/app/node_modules/connect-mongo/node_modules/mongodb/lib/core/sdam/topology.js:439:30)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:33) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:33) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Can you please help on how to use autoconnect option so that I don't see this error but it will try to reconnect to mongodb so that once mongodb is up and running it can continue...?

@hnviradiya
Copy link
Author

Moreover I am also unable to find documentation on how to handle exception. If I could handle the exception then I also I would have tried to create mongo db session again from catch block.

@mingchuno
Copy link
Collaborator

Connecting to mongodb and connection state handling it outside the scope of the liv (or even express-session). Mongoose seems to have functionality to help you manage the connection retry and heartbeat interval. You can take a look into that. https://mongoosejs.com/docs/api/mongoose.html#mongoose_Mongoose-connect

@stale
Copy link

stale bot commented Apr 28, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 28, 2022
@stale stale bot closed this as completed Jun 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants