当我在 shell 中运行 mongodb 查询时,我会在几毫秒内得到结果集。当我在 codeigniter 中执行相同的查询时,我会在 12 秒内得到结果。
Shell 脚本
db.order.find({customer_email:/^<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e2839186a2839186cc818d8f" rel="noreferrer noopener nofollow">[email protected]</a>/}).explain()
Codeigniter 脚本
$orderData = $this->mongo_db->get_where('order', array('customer_email'=> new MongoRegex("/^<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dfbeacbb9fbeacbbf1bcb0b2" rel="noreferrer noopener nofollow">[email protected]</a>/i")));
有什么解决方案可以优化获取结果的速度吗? 总共有 7272699 条记录,我需要查找 [email protected] .
最佳答案
首先,您应该在 customer_email 上设置索引(如果尚未设置)。其次,尝试删除 MongoRegex 中的 i 标志以使用索引:
$orderData = $this->mongo_db->get_where('order', array('customer_email'=> new MongoRegex("/^<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6a0b190e2a0b190e44090507" rel="noreferrer noopener nofollow">[email protected]</a>/")));
关于php - Codeigniter mongodb 性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21456540/