const timeoutError = new error_1.MongoServerSelectionError(`Server selection timed out after ${serverSelectionTimeoutMS} ms`, this.description);
^
MongoServerSelectionError: connect ECONNREFUSED ::1:27017
at Timeout._onTimeout (D:\Coding\web\node_modules\mongodb\lib\sdam\topology.js:293:38)
at listOnTimeout (node:internal/timers:564:17)
at process.processTimers (node:internal/timers:507:7) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'localhost:27017' => ServerDescription {
_hostAddress: HostAddress { isIPv6: false, host: 'localhost', port: 27017 },
address: 'localhost:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 72838933,
lastWriteDate: 0,
error: MongoNetworkError: connect ECONNREFUSED ::1:27017
at connectionFailureError (D:\Coding\web\node_modules\mongodb\lib\cmap\connect.js:379:20)
at Socket.<anonymous> (D:\Coding\web\node_modules\mongodb\lib\cmap\connect.js:302: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) {
[Symbol(errorLabels)]: Set(0) {}
}
}
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
logicalSessionTimeoutMinutes: undefined
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
}
Node.js v18.7.0
[nodemon] app crashed - waiting for file changes before starting...
Code is:
const mongoose = require("mongoose");
const MongoUrl = "mongodb://localhost:27017";
const mongoConnect = () => {
// mongoose.connect(
// MongoUrl,
// { useNewUrlParser: true, useUnifiedTopology: true, family:
4 },
// (err) => {
// if (!err) {
// console.log("Connected");
// } else {
// console.log("?Not connected", err);
// }
// }
// );
mongoose.connect(MongoUrl, (err)=>{
if(!err)
{
console.log("Connected");
}
else{
console.log("not");
}
})
};
mongoConnect();