2015-08-25

MongoDB - Index management commands


db.COLLECTION_NAME.getIndexes();

db.COLLECTION_NAME.createIndex( { FIELD_NAME:1 } );

db.COLLECTION_NAME.dropIndex( { FIELD_NAME:1 } ); // use same creation signature


// Background index creation (no read locks, no write locks, a bit slower)
db.COLLECTION_NAME.createIndex( { FIELD_NAME:1 }, {background:true} );

// Compound index creation
db.COLLECTION_NAME.createIndex( { FIELD_NAME:1, FIELD_NAME_2:-1 } );


// Sub-document index creation
db.COLLECTION_NAME.createIndex( { 'FIELD_NAME.SUB_FIELD_NAME':1} );


PS. Number 1 represents an ascending-order index, while -1 a descending-order one.

No comments:

Post a Comment