Mongodb慢计数查询

时间:2017-12-16 12:27:02

标签: mongodb

我有一个包含200万条记录的集合:

{
    "_id" : ObjectId("5a2bcdde0fab483921eeda9b"),
    "body" : "a big text is here ///",
    "txt_filename" : "/home/ehsan/data/pubmed_data/txt_data/Nutr_Res/Nutr_Res_2013_Mar_33(3)_188-194.txt",
    "processed" : true,
    "xml_filename" : "",
    "type" : "comm"
}

当我想执行此命令时:

db.articles.count({processed: true})

花了几分钟才看到结果。什么原因?我需要在桌子上放一个索引吗?我可以在几毫秒内在Elasticsearch中查询。 MongoDB有什么问题?

1 个答案:

答案 0 :(得分:1)

您需要在字段(已处理)上创建索引,以便获得更快的结果。

创建索引:

if(t1.getRegion().contains((int) touchX, (int) touchY))

您可以参考以下链接获取更多信息。 mongodb count vs find with count

相关问题