in lib/MongoManager.ts [19:42]
private async connect(host: Host) {
const urlStr = host.path.startsWith('mongodb')
? host.path
: `mongodb://${host.path}`;
const url = new URL(urlStr);
let hostname = url.host || host.path;
if (this._servers[hostname] instanceof Server) {
// Already connected
return;
}
try {
const client = new MongoClient(urlStr);
await client.connect();
const server = new Server(hostname, client);
this._servers[hostname] = server;
console.info(`[${hostname}] Connected to ${hostname}`);
await this.checkAuth(hostname);
} catch (err) {
console.error(`Error while connecting to ${hostname}:`, err.code, err.message);
this._servers[hostname] = err;
}
}