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
findAndModify atomically 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)