Unique Username

On the site I am designing, during registration, a custom text form field was added so the user can input a username. How do I set it up to check if the username is available or already taken?

Something like this - >

wixData.query("yourCollection")
  .eq("yourfield", $w('#input1').value)
  .find()
  .then( (results) => {
    if(results.items.length > 0) {
      console.log("userId taken");

    } else {
     console.log("User id available");  
    }
  } );