unique field in database

  1. Ok so I like to check if a customer already exists in the database and prevent adding if so.
    I changes some code I founf on this site but it doesn’t seem to work: Here is the code on a button click (test is on password field):

import wixData from ‘wix-data’;
export async function Customer_Info_beforeInsert(item, context) {
//build a query that counts items with the same value in the field
//“uniqueField” as the item we want to insert:
let valueToTest = item.uniqueField;
const numOfItems = await wixData.query(“password”)
.eq(“password”, valueToTest).count();

//if no items found, we can continue on with the insert operation
if (numOfItems === 0) return item;

//otherwise, reject the promise
Promise.reject("an item with value " + item.uniqueField

  • " in the field ‘uniqueField’ already found in the collection" );
  1. unfortunately I clicked on display success msg a few times in the data connection expecting something to happen. Now I need to remove the double entries. Where do I this?
    Thanks in advance

See the Prevent duplicates example to see how to keep from entering duplicates into a database collection.

Here’s how you can delete rows from a database collection: