MongoDB Index Use

Source: Internet
Author: User

for (Var i=0;i<10000;i++) {

Db.user.insert ({name: "User" +i,age:i})

} Add so much data

Db.user.find ({name: "user100"}) did not add an index to scan all data

Db.user.find ({name: "user100"}). Explain () can view information about using the index, such as the number of query bars, the time of the query

Db.user.ensureIndex ({name:1}) create index for name

Db.user.stats () See how the index is related

Db.user.find ({name: "user100"}) after the index is added, the scan line finds the

Db.user.dropIndex ({name:1}) Delete Index Table

If you delete a collection, name all the indexes on this collection are also deleted

Create a unique index, you cannot create an element with the same name value

Db.user.createIndex ({name:1},{unique:true})

MongoDB Index Use

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.