简体   繁体   English

MongoDB变得非常慢

[英]MongoDB gets very slow

I have a site which searches the website source codes. 我有一个搜索网站源代码的网站。 but when DB, gets more then 100 site, mongodb starts to work slower. 但是当DB,获得超过100个站点时,mongodb开始工作得更慢。

here is my code: 这是我的代码:

$arananlar = $db->kaynaklar->find(array("kaynak" => new MongoRegex("/".$kelime."/siU")))->sort(array("_id" => -1))->limit($kactane)->skip($alt);

The usual way to speed up searches is by adding an index. 加快搜索速度的常用方法是添加索引。 But indexes can't help when you use regular expressions. 但是当您使用正则表达式时,索引无法帮助您。 An index only helps you when you know exactly what you search for. 只有当您确切知道搜索内容时,索引才能帮助您。 But regular expressions are much more complex than that. 但正则表达式要复杂得多。 They need to read the whole content of each string for a match ( exception: when the regular expression starts with the start-of-string anchor ^ ). 他们需要读取每个字符串的全部内容以进行匹配( 例外:当正则表达式以字符串开始锚点^ )。

But when you don't need the full power of regular expressions and only search for complete words, you can create a text index and use text search . 但是,如果您不需要正则表达式的全部功能并且只搜索完整的单词,则可以创建文本索引并使用文本搜索

When you want to know if a specific query uses an index or not, you can use the explain method of the cursor. 当您想知道特定查询是否使用索引时,可以使用游标的explain方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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