title: Mongoose auto increment
body: <p>According to <a href="http://docs.mongodb.org/manual/tutorial/create-an-auto-incrementing-field/" rel="noreferrer">this mongodb article</a> it is possible to auto increment a field and I would like the use the counters collection way.</p>
  
  <p>The problem with that example is that I don't have thousands of people typing the data in the database using the mongo console. Instead I am trying to use mongoose.</p>
  
  <p>So my schema looks something like this:</p>
  
  <pre><code>var entitySchema = mongoose.Schema({
    testvalue:{type:String,default:function getNextSequence() {
          console.log('what is this:',mongoose);//this is mongoose
          var ret = db.counters.findAndModify({
                   query: { _id:'entityId' },
                   update: { $inc: { seq: 1 } },
                   new: true
                 }
          );
          return ret.seq;
        }
      }
  });
  </code></pre>
  
  <p>I have created the counters collection in the same database and added a page with the _id of 'entityId'. From here I am not sure how to use mongoose to update that page and get the incrementing number.</p>
  
  <p>There is no schema for counters and I would like it to stay that way because this is not really an entity used by the application. It should only be used in the schema(s) to auto increment fields.</p>