I have a NodeJS application that uses Mongoose to store (small amounts of) data on my MongoDB database. I use Nodemon to automatically restart the server when any file in my project is saved. I type npm start
in my VSCode terminal when I first open it, and usually leave it until I quit VSCode. After some times that I make the server restart automatically, my application stops connecting to MongoDB. It's been happening since I've started using Mongo and I still haven't found a solution to this. This is the error I get, after some time that the application is trying to connect to a Mongo database:
C:\Users\enric\Desktop\NodeJS Course\Section 14 - Sessions and Cookies\Online Shop Website\node_modules\mongodb\lib\utils.js:671
throw error;
^
Error: Error connecting to db: queryTxt ETIMEOUT nodecoursecluster.lmj6z.mongodb.net
at C:\Users\enric\Desktop\NodeJS Course\Section 14 - Sessions and Cookies\Online Shop Website\node_modules\connect-mongodb-session\index.js:78:17
at C:\Users\enric\Desktop\NodeJS Course\Section 14 - Sessions and Cookies\Online Shop Website\node_modules\mongodb\lib\utils.js:668:9
at C:\Users\enric\Desktop\NodeJS Course\Section 14 - Sessions and Cookies\Online Shop Website\node_modules\mongodb\lib\mongo_client.js:225:23
at C:\Users\enric\Desktop\NodeJS Course\Section 14 - Sessions and Cookies\Online Shop Website\node_modules\mongodb\lib\operations\connect.js:284:21
at QueryReqWrap.callback (C:\Users\enric\Desktop\NodeJS Course\Section 14 - Sessions and Cookies\Online Shop Website\node_modules\mongodb\lib\core\uri_parser.js:90:18)
at QueryReqWrap.onresolve [as oncomplete] (node:dns:203:10)
[nodemon] app crashed - waiting for file changes before starting...
Is there any way I can fix this?
(I'll definitely provide any additional needed information if anyone asks.)
I was able to fix this by changing the DNS to Google's 8888 8844. I followed this video.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.