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

239
Views
What is the correct way to check for duplicate entries in Mongoose?

I'm fetching an API, and I want to store the result in my own DB. I need to check for duplicates, but my code did not find them.

Here is my code :


function parseAlertsReceived(JsonAlertArray) {
  let alerts = []
  let id, software, version

  for (let i = 0; i < JsonAlertArray.length; i++) {
    id = JsonAlertArray[i]['id']
    
    if ( !isDuplicate(id) ) {
      
      for (let j = 0; j < JsonAlertArray[i]['vulnerable_configuration'].length; j++) {
        if (null != (JsonAlertArray[i]['vulnerable_configuration'][j])) {
          software = getAlertSoft(JsonAlertArray[i]['vulnerable_configuration'][j])
          version  = getAlertVersion(JsonAlertArray[i]['vulnerable_configuration'][j])            
          alerts.push( new cveAlert(id, software, version) )
        }
      }
    }
  } 
function isDuplicate(id_) {
 cveAlertCollection.find({id: id_ } ).count()
      .then( res => occurences = res)
      .then(() => console.log( "Is it a duplicate id ? : " + occurences > 0 ))
  return (occurences > 0)
  }

With the same JsonAlertArray, I should have all entries added at the first update, then no entries if I call the function again since there all entries are already stored.

However, isDuplicate() always return false.

Here is a sample of the JsonArray : https://cve.circl.lu/api/last

about 4 years ago · Juan Pablo Isaza
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!