Created
July 4, 2013 10:39
-
-
Save rajesh-gonuguntla/5926685 to your computer and use it in GitHub Desktop.
Changing indexes in mongodb
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
To change indexes in mongodb, first of all you may need to drop current index and then ensure to index on the attributes you want the index. | |
How to drop an index: | |
db.things.dropIndex("field/attributename"); | |
How to add index of the new fields : | |
db.things.ensureIndex({field1:1, field2:1},{unique:true}); | |
It need not to be a unique index but above is an example creating a composite unique index in mongodb. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment