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

114
Views
Getting message exist in console while UID is not in database

I am trying to check if the UID exists in db. If it exist I want it not to write a data else write a data.

But for some reason I am getting exist when there is no such UID.

enter image description here

async function engagements(){
    // const db =  ;
    if (await Engagements.find({uid:"f60c7612-93f5-48b6-8039-94cf5668f6b4"})) {
        console.log("exist");
    }else{
        console.log("does not exist");
    }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I found the solution. The case that .find() returns an empty array which is equal to true. Basically I made a const and checked the array if it is empty or not

const db =  await Engagements.find({uid:"f60c7612-93f5-48b6-8039-94cf5668f6b4"});
    if (db.length > 0) {
        console.log("exist");
    }else{
        console.log("does not exist");
    }
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!