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

109
Views
async/await display data in global scope

This is my first time using promises and mongoose, and I'm trying to save data to global variable for later use

const getUser = async () => {
    let user 
    try {
       user = await clientModel.findOne({username: email})
       consoe.log(user) 
    } catch (e) {
      console.log(e)
    }
    return  user
  }

  const filteredUser = getUser().then((value) => {
    return value
  }).catch((e) => console.log(e));

  console.log(filteredUser)

user console log displays content:

{
  _id: new ObjectId("61aa75c64e1526131d98f2a1"),
  username: 'paul@beatles.uk',
  chequing: null,
  saving: '1000022',
  __v: 0
}

but filteredUser keeps displaying Promise { <pending> }

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to resolve promise for use data. Read about that here

It can be await or then

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!