**При попытке подключения к БД выходит следующая ошибка.
Ubuntu 22
MongoDB CE 6.0
NodeJS 22.3.0
package.json:
“mongodb”: “^6.7.0”,
“mongodb-core”: “^3.2.7”,**
Давно так подключался, все работало, прошло много времени решил снова попробовать, но проблема на проблеме
[LOG] Start of module 'mongo.js'..
[MongoDB] Starting the database..
(node:1346) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
/root/tg/node_modules/mongodb/lib/sdam/topology.js:303
const timeoutError = new error_1.MongoServerSelectionError(`Server selection timed out after ${options.serverSelectionTimeoutMS} ms`, this.description);
^
MongoServerSelectionError: connect ECONNREFUSED 147.45.158.28:27017
at Topology.selectServer (/root/tg/node_modules/mongodb/lib/sdam/topology.js:303:38)
at async Topology._connect (/root/tg/node_modules/mongodb/lib/sdam/topology.js:196:28)
at async Topology.connect (/root/tg/node_modules/mongodb/lib/sdam/topology.js:158:13)
at async topologyConnect (/root/tg/node_modules/mongodb/lib/mongo_client.js:204:17)
at async MongoClient._connect (/root/tg/node_modules/mongodb/lib/mongo_client.js:217:13)
at async MongoClient.connect (/root/tg/node_modules/mongodb/lib/mongo_client.js:142:13)
at async MongoClient.connect (/root/tg/node_modules/mongodb/lib/mongo_client.js:295:16) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'147.45.158.28:27017' => ServerDescription {
address: '147.45.158.28:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
minRoundTripTime: 0,
lastUpdateTime: 136565,
lastWriteDate: 0,
error: MongoNetworkError: connect ECONNREFUSED 147.45.158.28:27017
at connectionFailureError (/root/tg/node_modules/mongodb/lib/cmap/connect.js:353:20)
at Socket.<anonymous> (/root/tg/node_modules/mongodb/lib/cmap/connect.js:268:44)
at Object.onceWrapper (node:events:635:26)
at Socket.emit (node:events:520:28)
at emitErrorNT (node:internal/streams/destroy:170:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
[Symbol(errorLabels)]: Set(1) { 'ResetPool' },
[cause]: Error: connect ECONNREFUSED 147.45.158.28:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1607:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '147.45.158.28',
port: 27017
}
},
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,
[Symbol(errorLabels)]: Set(0) {},
[cause]: MongoNetworkError: connect ECONNREFUSED 147.45.158.28:27017
at connectionFailureError (/root/tg/node_modules/mongodb/lib/cmap/connect.js:353:20)
at Socket.<anonymous> (/root/tg/node_modules/mongodb/lib/cmap/connect.js:268:44)
at Object.onceWrapper (node:events:635:26)
at Socket.emit (node:events:520:28)
at emitErrorNT (node:internal/streams/destroy:170:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
[Symbol(errorLabels)]: Set(1) { 'ResetPool' },
[cause]: Error: connect ECONNREFUSED 147.45.158.28:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1607:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '147.45.158.28',
port: 27017
}
}
}
файл mongo.js
const clc = require("cli-color");
console.log(clc.blue("[LOG] ") + "Start of module 'mongo.js'..");
let MongoClient = require("mongodb").MongoClient, db;
console.log(clc.magenta("[MongoDB] ") + "Starting the database..");
MongoClient.connect(
"mongodb://root:[email protected]:27017/?authSource=admin&readPreference=primary",
function (err, database) {
if (err)
return console.log(
clc.red("[MongoDB] [ERROR]") + "DB loading error: " + err
);
db = database.db("users");
db.stats(async (err, res) => {
if (err) {
return console.log(clc.red("[MongoDB] [ERROR]n") + err);
}
await console.log(
clc.magenta("[MongoDB] ") + `Successful connection to DB (${res.db})`
);
await console.log(
clc.magenta("[MongoDB] ") + `Collections': ${res.collections}`
);
await console.log(clc.magenta("[MongoDB] ") + `Objects': ${res.objects}`);
await console.log(
clc.magenta("[MongoDB] ") +
`Database size (${(res.dataSize / 1024 / 1024).toFixed(2)}) MBn`
);
await console.log(
clc.red("[SYSTEM] ") + "The Bot was successfully launched"
);
});
}
);
module.exports = function () {
return db;
};
**Менял версию NodeJS ниже, не помогло. **
New contributor
Владимир Сидоренко is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.