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

427
Views
Mongoose custom virtual field return promise

I'm new in mongoDB, I have virtual field like this

videoSchema.virtual('playURL').get(async function () {
    return await getVideoURLbyId(this.video_id, true)
        .then(res => res)
})

videoSchema.set('toObject', { virtuals: true })
videoSchema.set('toJSON', { virtuals: true })

I can log the result but when show on browser, it shows empty result playURL:{}. How to fix it?

Thank you

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Not possible use asynchronous in Virtual look this issue, because virtuals are just getters/setters, which are assumed to be synchronous. Use a custom method instead

over 4 years ago · Santiago Trujillo 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!