Skip to content

Instantly share code, notes, and snippets.

@rajesh-gonuguntla
Created July 4, 2013 10:39
Show Gist options
  • Save rajesh-gonuguntla/5926685 to your computer and use it in GitHub Desktop.
Save rajesh-gonuguntla/5926685 to your computer and use it in GitHub Desktop.
Changing indexes in mongodb
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