Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

63
Views
Await Receiving Warning while in try-catch Block

The first await below generates the warning 'await' has no effect on the type of this expression if I do not include the .catch line immediately found after (and currently commented out). However, all the code is included in a try-catch block. Why am I receiving this warning? Isn't the MongoClient.connectan asynchronous call?

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()
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

.connect() returns a promise not a client. Try this code:

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()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!