1 Creating an Index
1 is a positive-order index, and 1 is a negative-order index
Indexing increases query time by pressing, reducing insertion time
Db.books.ensureIndex ({number:1})
2. Create an index, specify a name
Db.book.ensureIndex ({name:-1},{name: "BookName"})
3. Unique index
Db.books.ensureIndex ({name:1},{unique:true})
4. Remove duplicate values
Db.books.ensureIndex ({name:1},{unique:true,dropdups:true})
5. Specifying an index for querying
Db.books.find ({no:1}). Hint ({no:1})
6. What query index is currently used
Db.books.find ({no:1}). Explain ()
7. Index of production look
Db.system.indexes.find ()
8. Creating an index locks the table, allowing the creation of an index to be resolved in the background
Db.books.ensureIndex ({number:1},{background:true})
9. Deleting an index
Db.runcommand ({dropindexes: "Books", Index: "No_1"})
MongoDB Index (5)