title: Find unique username with recursion
body: <p>I am trying to determine if recursion works well in my use case below.</p>
  
  <p>I am passed in <code>firstName</code> as a parameter and i generate a unique username for my user.</p>
  
  <pre><code>getUniqueUsername: function(firstName) {
  
      if (!firstName) {
          var randomNum = Math.floor(Math.random() * 9000) + 1000;
          var username = firstName.substring(0, 4) + randomNum;
  
          // check if username is already used - using recursion evaluate for performance
          var user = Users.find({username: username}, {"_id": 1});
          if (user) {
              //call recursion method here
          }
          return username
      } else {
          return "";
      }
  }
  </code></pre>
  
  <p>Are there better ways to keep generating and querying the DB until a unique username is found. I thought of a recursion call to the same method when <code>user</code> returns true but looking for possible better ways.</p>