Open amitrao91 opened 1 year ago
check if you have a valid mongodb connection string in your config.env file (Backend> Config> config.env) For eg: (Your config.env should have valid values for all the below variables (assuming you have local version of Mongodb)
PORT=
NODE_ENV=
DB_URI=mongodb://localhost:27017/
every time my code is working fine but after few second it is showing ""
"const serverSelectionError = new ServerSelectionError(); ^
MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 at Connection.openUri (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\connection.js:825:32) at C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:417:10 at C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5 at new Promise () at promiseOrCallback (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\helpers\promiseOrCallback.js:40:10) at Mongoose._promiseOrCallback (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:1270:10) at Mongoose.connect (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:416:20) at connectDatabase (C:\Users\Amit Rao\Desktop\MERN PROJECT\backend\config\database.js:5:6) at Object. (C:\Users\Amit Rao\Desktop\MERN PROJECT\backend\server.js:10:1) at Module._compile (node:internal/modules/cjs/loader:1218:14) { reason: TopologyDescription { type: 'Unknown', servers: Map(1) { 'localhost:27017' => ServerDescription { address: 'localhost:27017', type: 'Unknown', hosts: [], passives: [], arbiters: [], tags: {}, minWireVersion: 0, maxWireVersion: 0, roundTripTime: -1, lastUpdateTime: 6053295, lastWriteDate: 0, error: MongoNetworkError: connect ECONNREFUSED ::1:27017 at connectionFailureError (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongodb\lib\cmap\connect.js:387:20) at Socket. (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongodb\lib\cmap\connect.js:310:22) at Object.onceWrapper (node:events:628:26) at Socket.emit (node:events:513:28) at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { cause: Error: connect ECONNREFUSED ::1:27017 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1283:16) { errno: -4078, code: 'ECONNREFUSED', syscall: 'connect', address: '::1', port: 27017 }, [Symbol(errorLabels)]: Set(1) { 'ResetPool' } }, topologyVersion: null, setName: null, setVersion: null, electionId: null, logicalSessionTimeoutMinutes: null, primary: null, me: null, '$clusterTime': null } }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, setName: null, maxElectionId: null, maxSetVersion: null, commonWireVersion: 0, logicalSessionTimeoutMinutes: null }, code: undefined } Node.js v19.2.0 [nodemon] app crashed - waiting for file changes before starting..."
Check above comment, it will help. Thanks
every time my code is working fine but after few second it is showing ""
"const serverSelectionError = new ServerSelectionError(); ^
MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 at Connection.openUri (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\connection.js:825:32) at C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:417:10 at C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5)
at promiseOrCallback (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\helpers\promiseOrCallback.js:40:10)
at Mongoose._promiseOrCallback (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:1270:10)
at Mongoose.connect (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:416:20)
at connectDatabase (C:\Users\Amit Rao\Desktop\MERN PROJECT\backend\config\database.js:5:6)
at Object. (C:\Users\Amit Rao\Desktop\MERN PROJECT\backend\server.js:10:1)
at Module._compile (node:internal/modules/cjs/loader:1218:14) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'localhost:27017' => ServerDescription {
address: 'localhost:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 6053295,
lastWriteDate: 0,
error: MongoNetworkError: connect ECONNREFUSED ::1:27017
at connectionFailureError (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongodb\lib\cmap\connect.js:387:20)
at Socket. (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongodb\lib\cmap\connect.js:310:22)
at Object.onceWrapper (node:events:628:26)
at Socket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
cause: Error: connect ECONNREFUSED ::1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1283:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 27017
},
[Symbol(errorLabels)]: Set(1) { 'ResetPool' }
},
topologyVersion: null,
setName: null,
setVersion: null,
electionId: null,
logicalSessionTimeoutMinutes: null,
primary: null,
me: null,
'$clusterTime': null
}
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}
Node.js v19.2.0
[nodemon] app crashed - waiting for file changes before starting..."
at new Promise (