title: Incremental field to existing collection
body: <p>I have a collection containing around 100k documents. I want to add an auto incrementing "custom_id" field to my documents, and keep adding my documents by incrementing that field from now on.</p>
  
  <p>What's the best approach for this? I've seen some examples in the official document (<a href="http://docs.mongodb.org/manual/tutorial/create-an-auto-incrementing-field/" rel="nofollow">http://docs.mongodb.org/manual/tutorial/create-an-auto-incrementing-field/</a>) however they're only for adding new documents, not for updating an existing collection.</p>
  
  <p>Example code I created based on the link above to increment my counter:</p>
  
  <pre><code>function incrementAndGetNext(counter, callback) {
      counters.findAndModify({
          name: counter
      }, [["_id", 1]], {
          $inc: {
              "count": 1
          }
      }, {
          "new": true
      }, function (err, doc) {
          if (err) return console.log(err);
          callback(doc.value);
      })
  }
  </code></pre>
  
  <p>On the above code <code>counters</code> is <code>db.counters</code> collection and I have this document there:</p>
  
  <pre><code>{_id:"...",name:"post",count:"0"}
  </code></pre>
  
  <p>Would love to know.</p>
  
  <p>Thank you.</p>
  
  <p>P.S. I'm using native mongojs driver for js</p>