Estoy obteniendo una API y quiero almacenar el resultado en mi propia base de datos. Necesito buscar duplicados, pero mi código no los encontró.
Aquí está mi código:
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) }Con el mismo JsonAlertArray, debería agregar todas las entradas en la primera actualización, luego no hay entradas si vuelvo a llamar a la función, ya que todas las entradas ya están almacenadas.
Sin embargo, isDuplicate() siempre devuelve falso.
Aquí hay una muestra de JsonArray: https://cve.circl.lu/api/last