title: Mongoose create document if doesn't exist
body: <p>I am making a simple url shortener(Mong db, Node js).
  Here is my model:</p>
  
  <pre><code>var urlSchema = new mongoose.Schema({
      shortUrl: String,
      longUrl: String,
      created: {
          type: Date, default: Date.now
      },
      clicks: {
          type: Number, default: 0
      }
  });
  </code></pre>
  
  <p>I have a function getRandomString6()  that returns 6 random characters string.</p>
  
  <pre><code>var string = getRandomString6();
  </code></pre>
  
  <p>I want to implement this "pseudocode" algorithm:</p>
  
  <pre><code>1 var string = getRandomString6();
  2 if there is document with shortUrl == string
  3       go to step 1
  4 else
  5       create new document with shortUrl=string
  </code></pre>
  
  <p>How to do that?</p>