title: Creating/Updating Sequences - MongoDB
body: <p>I have created a 'sequence' collection. It has 'name' and 'counter' fields. The 'name' field is set to 'Tag' and 'counter' field is set to 0. Following is the code within a method that returns the next value of 'counter' field.</p>
  
  <pre><code>final Sequence tagSequence = mongoTemplate.findAndModify(
    new Query(Criteria.where("name").is("Tag")), 
    new Update().inc("counter", 1), 
    new FindAndModifyOptions().returnNew(true), Sequence.class);
  </code></pre>
  
  <p>However, this piece of code does not work. Any inputs?</p>
  
  <p>I found an implementation for this here, <a href="http://dev.bubblemix.net/blog/2011/04/auto-increment-for-mongodb-with-the-java-driver/" rel="nofollow">http://dev.bubblemix.net/blog/2011/04/auto-increment-for-mongodb-with-the-java-driver/</a>, however, I wanted to know what is wrong with this piece of code.</p>