2014-01-30 37 views
2

當我在shell中運行我的mongodb查詢時,我在幾毫秒內得到結果集。當我在codeigniter中執行相同的查詢時,我在12秒內得到結果。codeigniter mongodb性能

shell腳本

db.order.find({customer_email:/^[email protected]/}).explain() 

笨腳本

$orderData = $this->mongo_db->get_where('order', array('customer_email'=> new MongoRegex("/^[email protected]/i"))); 

是否有任何解決方案,優化獲取結果的速度? 總共有7272699條記錄,我需要找到[email protected]

回答

2

首先,你應該在customer_email上設置一個索引(如果還沒有的話)。其次,儘量去除I標誌MongoRegex使用索引:

$orderData = $this->mongo_db->get_where('order', array('customer_email'=> new MongoRegex("/^[email protected]/"))); 
+0

嗨STEYX,除去我旗它提高了性能之後,但我需要在不區分大小寫的搜索數據。 –

+0

然後查詢不能使用索引。另一種解決方案是在寫入mongo之前總是使用小寫的customer_email。 – Steyx

+0

謝謝。有效。 –