[英]Find hundreds of records among millions in MongoDB
I have a mongodb table that contains currently 11 millions of records. 我有一个mongodb表,其中包含当前1100万条记录。
{
"_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) : 我想获取isVerified
等于0
(几百个)的所有记录:
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. 问题是查询需要12秒才能结束,并且我的数据库将来会大大增加。
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/ 更多信息: https : //docs.mongodb.com/manual/reference/method/db.collection.createIndex/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.