title: MongoDB find lowest missing value
body: <p>I have a collection in MongoDB that looks something like:</p>
  <pre><code>{
   &quot;foo&quot;: &quot;something&quot;,
   &quot;tag&quot;: 0,
  },
  {
   &quot;foo&quot;: &quot;bar&quot;,
   &quot;tag&quot;: 1,
  },
  {
   &quot;foo&quot;: &quot;hello&quot;,
   &quot;tag&quot;: 0,
  },
  {
   &quot;foo&quot;: &quot;world&quot;,
   &quot;tag&quot;: 3,
  }
  </code></pre>
  <p>If we consider this example, there are entries in the collection with <code>tag</code> of value <code>0</code>, <code>1</code> or <code>3</code> and these aren't unique values, <code>tag</code> value can be repeated. My goal is to find that <code>2</code> is missing. Is there a way to do this with a query?</p>