Код: Выделить всё
const {MongoClient} = require('mongodb');
async function main(){
const uri = "mongodb://MyUserName:P@$$W0RD!@192.168.1.10:27017/?retryWrites=true&w=majority";
const client = new MongoClient(uri);
try {
// Connect to the MongoDB cluster
await client.connect();
// Make the appropriate DB calls
await listDatabases(client);
} catch (e) {
console.error(e);
} finally {
await client.close();
}
}
async function listDatabases(client){
databasesList = await client.db().admin().listDatabases();
console.log("Databases:");
databasesList.databases.forEach(db => console.log(` - ${db.name}`));
};
main().catch(console.error);
< /code>
Я получаю этот вывод: < /p>
MongoServerSelectionError: getaddrinfo ENOTFOUND tor!
at Topology.selectServer (
...
...
test.js:16:9) {
errorLabelSet: Set(0) {},
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) { 'tor!:27017' => [ServerDescription] },
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined,
[cause]: MongoNetworkError: getaddrinfo ENOTFOUND tor!
at Socket. (.....lib\cmap\connect.js:285:44)
at Object.onceWrapper (node:events:633:26)
at Socket.emit (node:events:518: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:90:21) {
errorLabelSet: Set(1) { 'ResetPool' },
beforeHandshake: false,
[cause]: Error: getaddrinfo ENOTFOUND tor!
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:120:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'tor!'
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... -enotfound