Created
December 16, 2010 04:07
-
-
Save victorbstan/743008 to your computer and use it in GitHub Desktop.
A couple of short commands to add unique constraints on sequential index fields in a mongoDB document
This file contains hidden or 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
| // Mongo shell | |
| // Let's say you need to have a sequential id; here, it is '_i' | |
| // the other entry is a reference to another 'post' containing its natural MongoDB ObjectId | |
| db.your_collection_name.insert({"_i":new NumberLong(1), "post_id":"4cf68ff393eae6291e00003a"}); | |
| // let's make sure we add an index that is defined as unique | |
| db.your_collection_name.ensureIndex({"_i":1}, {unique:true}); | |
| // TODO: still need to provide the methodology used to auto-increment the unique field '_i' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment