Last active
August 29, 2015 14:14
-
-
Save pjvds/0a7d6fe1e943fa0a2dda to your computer and use it in GitHub Desktop.
in-line auto increment in mongodb
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
db.docs.insert({ | |
_id: db.counter.findAndModify({ | |
query: { _id: 'docs' }, | |
update: { $inc: { seq: 1 } }, | |
new: true, | |
upsert: true | |
}).seq | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment