简体   繁体   中英

Find hundreds of records among millions in MongoDB

I have a mongodb table that contains currently 11 millions of records.

    {
            "_id": "5a0dc8528b7f1f00102b5006",
            "timestamp": "2017-08-25T03:49:37.000Z",
            "value": 150,  
            "isVerified": 0
    }

I want to fetch all the records where isVerified is equal to 0 (few hundreds) :

db.getCollection('record').find({"isVerified" : 0})

The problem is that the query takes 12 seconds to end and my database will increase significantly in the future.

How can I accelerate the process ?

You need to create an index :

db.getCollection('record').createIndex({"isVerified" : 1})

More info : https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM