这有点奇怪。 我正在迭代一个相当大的数据库,使用查询是否存在某些元素。在没有提示的情况下在数据库中运行此查询大约需要137秒,但是提示它会降低到0(这是优选的)。通过php使用它时
$collection->find($params)->hint(array("responses" => 1))->count();
并分析我得到的查询:
{“ts”:ISODate(“2012-05-08T10:11:24.682Z”),“op”:“command”,“ns”: “ey_gsat。$ cmd”,“command”:{“count”:“survey_answers”,“query”:{ “respond.93”:{“$ exists”:true},“responses.96”:{“$ exists”: true},“responses.99”:{“$ exists”:true},“responses.102”:{ “$ exists”:true},“responses.105”:{“$ exists”:true}, “responses.108”:{“$ exists”:true},“responses.111”:{“$ exists” :true},“responses.114”:{“$ exists”:true},“responses.117”:{ “$ exists”:true},“responses.120”:{“$ exists”:true}, “respond.1”:{“$ exists”:true}}},“ntoreturn”:1, “responseLength”:48,“millis”:137,“client”:“127.0.0.1”,“user” :“”}
通过php运行时,没有任何查询实际使用索引的迹象。我在这个网站上运行了很多这样的查询,所以137毫秒都加起来,因此我想优化它们。任何想法可能出错?
答案 0 :(得分:0)
这是已知的计数限制:https://jira.mongodb.org/browse/SERVER-2677。您可能想关注/投票支持该问题。不幸的是,没有解决方法。您可能希望尽可能考虑缓存计数或估算总数。