Last active
August 29, 2015 14:01
-
-
Save mrbitsdcf/6243cc7065159d392084 to your computer and use it in GitHub Desktop.
Auto-increment function for MongoDB console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function counter(name) { | |
return db.counters.findAndModify( | |
{query:{_id:name}, | |
update:{$inc : {next:1}}, | |
new:true, | |
upsert:true} | |
).next; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment