2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-03 15:40:17 +00:00
cheat.sheets/sheets/_mongo/index
2018-01-06 17:19:18 +00:00

20 lines
422 B
Plaintext

// Create an index
db.books.createIndex({title:1})
// Type 1 means ascending; -1 means descending
// Create a unique index
db.books.createIndex( {isbn:1},{unique:true} )
// Create a index on multiple fields (compound index)
db.books.createIndex({title:1, author:-1})
// Show all indexes in a collection
db.books.getIndexes()
// Drop an index
db.books.dropIndex({author:-1})
// Show index statistics
db.books.stats()