Check for duplicates before saving them on database

@sabrinaamazon
As Rajjat Garg already mentioned, run your code on a LIVE-SITE.
If you are using Google-ChromePRESS F-12 and navigate to → CONSOLE .

import wixData from 'wix-data';
import wixUsers from 'wix-users';

$w.onReady(function() {console.log("Page-Ready!")
  let user = wixUsers.currentUser; console.log("USER: ", user);
  user.getPricingPlans() 
  .then((pricingPlans)=> {console.log("Pricing-Plans: ", pricingPlans);
    let firstPlan = pricingPlans[0];  console.log("First-Plan: ", firstPlan);
    let  planName = firstPlan.name;   console.log("Plan-Name: ", planName);

    if (planName == '7 DAY FREE TRIAL $0'){console.log("Showing FREE-PLAN);
      $w('#text30, #text31').show();
      $w('#dropdown1, #emailInput, #button1').show();
      //searchForDuplicityFreePlan(); 
    }
    
    if(planName == 'BASIC'){console.log("Showing BASIC-PLAN);
      $w('#text30, #text31, #emailInput2, #button2').show();
      $w('#dropdown2, #dropdown3, #dropdown4').show();
      //searchForDuplicityBasicPlan();      
    }  


    // This Code-Part runs only when clicked onto submission-button...
    $w("#dataset1").onBeforeSave(async()=> {console.log("Submission-Button clicked, on beforeSave() for DATASET-1 (RegionSelectionQuizFree) running...");
      let checkEmailFree = await checkDatabase('RegionSelectionQuizFree', 'email', $w("#emailInput").value);
      console.log("Email-Check-Free-Result: ", checkEmailFree);
      let fieldCheck = $w("#dropdown1").value; console.log("Field-Check-Result: ", fieldCheck);

      if(checkEmailFree === false){console.log("FALSE running...");
        $w("#text32").text = "An error occurred. You have already submitted this form";
        return false     
      } else{console.log("ELSE-EmailCheck running... running...")}

      if(fieldCheck === ""){console.log("FALSE running...");
        $w("#text32").text = "An error occurred. Please select your region of interest";
        return false       
      } else{console.log("ELSE-FieldCheck running...")}
    });


    // This Code-Part runs only when clicked onto submission-button...
    $w("#dataset2").onBeforeSave(async() => {console.log("Submission-Button clicked, on beforeSave() for DATASET-2 (RegionSelectionQuizBasic) running...")
      let checkEmailBasic = await checkDatabase('RegionSelectionQuizBasic', 'email', $w("#emailInput2").value);
      console.log("Email-Check-Basic-Result: ", checkEmailBasic);
      let region1 = $w("#dropdown2").value, region2 = $w("#dropdown3").value, region3 = $w("#dropdown4").value;
      console.log("Region-1: ", region1);
      console.log("Region-2: ", region2);
      console.log("Region-3: ", region3);

      const regions = new Set(); console.log("Regions: ", regions);
      regions.add(region1);
      regions.add(region2);
      regions.add(region3);                
      regions.delete(""); 
      
      if(checkEmailBasic === false){
        $w("#text34").text = "An error occurred. You have already submitted this form";
        return false     
      } 

      if (regions.size !== 3) {
        $w("#text34").text = "An error occurred. Please select 3 different regions of interest";
        return false             
      }
    });
  });
});


function checkDatabase(collection, dbField, value) {console.log("Checking DATABASE...")
  wixData.query(collection)
  .eq(dbField, value)
  .find()
  .then((res)=>{console.log("RESULTS: ", res);
    if(res.items.length>0)  {return false} 
    else {return true}
  }).catch((err)=>{console.log(err);});
}

Please run that code and show what you get in console.
Also do not forget to OPEN THE 3-DOTS, so results can be investigated!
Show the results screenshot/screenshots.
Perhaps also show a related part of your DB to see the structure of your DB.