Untitled

mail@pastecode.io avatar
unknown
plain_text
8 months ago
492 B
3
Indexable
Never
const mongoUrl = 'mongodb://localhost:27017';

async function connectToMongoDB(database) {
    const client = new MongoClient(mongoUrl, {
        useNewUrlParser: true,
        useUnifiedTopology: true,
    });
    try {
        await client.connect();
        console.log('Connected to MongoDB');
        const dbName = `${database}`;
        return client.db(dbName);
    } catch (err) {
        console.error('Error connecting to MongoDB:', err);
        throw err;
    }
}
Leave a Comment