MongoDB Index (5)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.