When I try to test connection to MongoDB using Mongoose:
I get the following error:
[nodemon] restarting due to changes...
[nodemon] starting `node server.js`
Server is running on port: 5000
(node:12972) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [cluster0-shard-00-00-knpdv.mongodb.net:27017] on first connect [MongoNetworkError: read ECONNRESET]
at Pool.<anonymous> (C:\Users\ksethi014\projects\mernexercisetracker\backend\node_modules\mongodb-core\lib\topologies\server.js:431:11)
at Pool.emit (events.js:198:13)
at connect (C:\Users\ksethi014\projects\mernexercisetracker\backend\node_modules\mongodb-core\lib\connection\pool.js:557:14) at callback (C:\Users\ksethi014\projects\mernexercisetracker\backend\node_modules\mongodb-core\lib\connection\connect.js:109:5)
at runCommand (C:\Users\ksethi014\projects\mernexercisetracker\backend\node_modules\mongodb-core\lib\connection\connect.js:129:7)
at Connection.errorHandler (C:\Users\ksethi014\projects\mernexercisetracker\backend\node_modules\mongodb-core\lib\connection\connect.js:321:5)
at Object.onceWrapper (events.js:286:20)
at Connection.emit (events.js:198:13)
at TLSSocket.<anonymous> (C:\Users\ksethi014\projects\mernexercisetracker\backend\node_modules\mongodb-core\lib\connection\connection.js:321:10)
at Object.onceWrapper (events.js:286:20)
at TLSSocket.emit (events.js:198:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
(node:12972) 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(). (rejection id: 1)
(node:12972) [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.
Since everything seemed correct i tried to use your code to connect and it worked without a flaw^^
Most likely there’s something wrong with the atlas uri: you created your own cluster right? Did you also replaced the username:password with your actual username and password ( not only removing the angular brackets)?
(node:16820) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [cluster0-shard-00-00-knpdv.mongodb.net:27017] on first connect [MongoNetworkError: read ECONNRESET]
at Pool.<anonymous> (C:\Users\ksethi014\projects\mernexercisetracker\backend\node_modules\mongodb-core\lib\topologies\server.js:431:11)
at Pool.emit (events.js:198:13)
at connect (C:\Users\ksethi014\projects\mernexercisetracker\backend\node_modules\mongodb-core\lib\connection\pool.js:557:14)
at callback (C:\Users\ksethi014\projects\mernexercisetracker\backend\node_modules\mongodb-core\lib\connection\connect.js:109:5)
at runCommand (C:\Users\ksethi014\projects\mernexercisetracker\backend\node_modules\mongodb-core\lib\connection\connect.js:129:7) at Connection.errorHandler (C:\Users\ksethi014\projects\mernexercisetracker\backend\node_modules\mongodb-core\lib\connection\connect.js:321:5)
at Object.onceWrapper (events.js:286:20)
at Connection.emit (events.js:198:13)
at TLSSocket.<anonymous> (C:\Users\ksethi014\projects\mernexercisetracker\backend\node_modules\mongodb-core\lib\connection\connection.js:321:10)
at Object.onceWrapper (events.js:286:20)
at TLSSocket.emit (events.js:198:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
(node:16820) 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(). (rejection id: 1)
(node:16820) [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.
My terminal says:
TypeError: connection.once is not a function
at Object. (C:\Users\Lisa\Desktop\exercise-tracker\mern-exercise-tracker\backend\server.js:16:12)
I think my other problem is this:
In my .env file, I have pasted the ATLAS_URI= connection string from my mongodb Atlas file and it still isn’t working. I did not yet change the – I can’t figure out what the name should be! Can anyone help?