mongodb query optimization and index

explain

With this command you can figure out how to execute the query mongodb

db.the_table.find({"age":{"$gte":0}}).explain("executionStats")

    Pictures .png

    totalKeysExamined entire scan display index number is 0, docsExamined display 9 to scan the entire set of documents


You can create an index with ensureIndex () or createIndex (), which the old version with ensureIndex ()

    Pictures .png


getIndexes () method checks whether the index is successfully created:

    Pictures .png

    (Collection now has two indexes: the first is the standard _id index; the second is our num index created index names are called _id_ and num_1.)

    After setting the index view will change with explain:

        db.numbers.find({num:{"$gt":19995}}).explain("executionStats")

            Pictures .png

            Pictures .png

            Pictures .png









































Guess you like

Origin blog.51cto.com/5660061/2412648