La primera await a continuación genera la advertencia 'await' has no effect on the type of this expression si no incluyo la línea .catch que se encuentra inmediatamente después (y actualmente comentada). Sin embargo, todo el código está incluido en un bloque try-catch. ¿Por qué recibo esta advertencia? ¿No es MongoClient.connect una llamada asíncrona?
const db = null async function dbConnect() { try { const client = await MongoClient.connect(url, {useUnifiedTopology: true}) // .catch(err => { console.log(err) }) if (!client) throw new Error("Database Not Available") db = await client.db(dbName) } catch (err) { console.log(err) } } dbConnect().connect() devuelve una promesa, no un cliente. Prueba este código:
const db = null async function dbConnect() { try { const client = new MongoClient(url) await client.connect({useUnifiedTopology: true}) db = await client.db(dbName) } catch (err) { console.log(err) } } dbConnect()