oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.17k stars 2.68k forks source link

DNS Errors when trying to connect to a MongoDB URI #5498

Open robobun opened 1 year ago

robobun commented 1 year ago

I'm trying to connect to a Mongo Database Atlas but I'm getting a DNS error, on node.js it works just fine. ( it was working before i updated )

Output:

❯ bun run dev
$ bun --watch ./bot/src/bot.ts
[0.02ms] ".env"
Logging into discord...
Logged In
Connecting to database ...
mongodb+srv://***:***/?retryWrites=true&w=majority
error: srv lookup failed: Timeout while contacting DNS servers
 code: "DNS_ETIMEOUT"

Code:

import { Client } from "discord.js";
import mongoose from "mongoose";
import { IEventHandler } from "../handlers/eventHandler";
import BotSettingsModel from "../models/botSettings"; // Import your Mongoose model

export default {
    name: 'ready',
    once: true,
    async execute(client: Client) {
        console.log('Connecting to database ...');
        console.log(process.env.MONGO_URI)
        await mongoose.connect(process.env.MONGO_URI || '', { maxPoolSize: 20 })
        console.log("Connected to the database!");
        console.log(`Ready! Logged in as ${client.user?.tag}`);
        client.user?.setActivity(`PSO Brasil | League | Bot desenvolvido por @sueroo`);
    }
} as IEventHandler;

Originally reported on Discord: DNS Errors when trying to connect to a MongoDB URI

TheDanielMoli commented 7 months ago

Duplicate of https://github.com/oven-sh/bun/issues/8758 (the issue is in using the SRV record).

mongodb:// works.

mongodb+srv:// does not work.