title: Is there a way to add an incrementing id in one statement in MongoDB?
body: <p>So I got a small database, It's not going to grow much more and I'm trying to get one document from the db in an API that I implemented in python so that with a given document Id I retrieve the document in the db. However, I find it a little hard to put the user to write a random number from the db. All I require is a function that modifies each document by setting an id field and to Auto-Increment. As I said, it's not going to grow that much and the performance isn't really an issue here.</p>
  <p>So far what I've been able to do is this:</p>
  <pre><code>var i = 0
  db.MyCollection.update({},
                            {$set : {&quot;new_field&quot;:1}},
                            {upsert:false,
                            multi:true}
  i ++;),
  
  </code></pre>
  <p>I achieved to set an id field but it sets the same number to each document (the count of every document) So let's say that if the db has 10 docs, it'll set the Id to 10.</p>