简体   繁体   中英

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.

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.

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