Skip to content

Instantly share code, notes, and snippets.

@slivero
Created July 5, 2012 21:14
Show Gist options
  • Save slivero/3056470 to your computer and use it in GitHub Desktop.
Save slivero/3056470 to your computer and use it in GitHub Desktop.
A mongodb atomic counter
doc = { name : "order_no", value : 1}
db.Counters.save(doc)
db.Counters.findAndModify({query : { name : "order_no"}, update : { $inc : {value : 1}}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment