Anonymous
JavaScript mongodb client производит enotfound
Сообщение
Anonymous » 12 мар 2025, 21:41
Я пишу приложение JS, которое подключается к базе данных MongoDB. Эта база данных работает и подключается с помощью MongoDB Compass. Я даже написал сценарий Python, который подключается к базе данных без проблем.
Код: Выделить всё
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!'
}
}
}
Единственная вещь, которая меняет меня, это то, что имя хоста не 192.168.1.10, но это tor! Я не уверен, что происходит.
Подробнее здесь:
https://stackoverflow.com/questions/795 ... -enotfound
1741804898
Anonymous
Я пишу приложение JS, которое подключается к базе данных MongoDB. Эта база данных работает и подключается с помощью MongoDB Compass. Я даже написал сценарий Python, который подключается к базе данных без проблем.[code]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!' } } } [/code] Единственная вещь, которая меняет меня, это то, что имя хоста не 192.168.1.10, но это tor! Я не уверен, что происходит. Подробнее здесь: [url]https://stackoverflow.com/questions/79504599/javascript-mongodb-client-producing-enotfound[/url]