MongoDB Sequence Number Generators Using findAndModify and Spring Data
Yuan Ji:
I want a sequence number generator from MongoDB to give me unique sequence number. The operations are to return current sequence number and also increase the sequence number in the database. In MongoDB, command
findAndModifyatomically modifies and returns a single document. So we can use this command to query the sequence number and increase it by $inc function.
The solution is interesting and the post includes the Spring-ified code for it. But there’s no word of the possible issues this solution would run into related to contention to update the same record. Even with row level locking and things would be pretty bad for an app needing lots of sequence number. But with MongoDB’s database level locking, things could get pretty ugly.
Original title and link: MongoDB Sequence Number Generators Using findAndModify and Spring Data (©myNoSQL)
via: http://www.jiwhiz.com/post/2013/1/Add_A_Counter_To_MongoDB_With_Spring_Data