php - Codeigniter mongodb 性能

标签 php codeigniter mongodb

当我在 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/

相关文章:

javascript - 为什么 jQuery 在 PHP 文件中不起作用?

php - 使用 _POST 参数构建 SQL 查询

mysql - 如何从两个表创建 JSON 数据

mongodb - 错误 : queryTxt ETIMEOUT when connecting to MongoDb Atlas using mongoose

javascript - 来自数据库的数据以 html 标签而不是格式化文本显示在网页上

php - 在php中读取.dbf(Foxpro数据库文件)

php - 如何将 codeigniter 的 URL_TITLE 值应用到 URL

php - 使用 codeigniter 显示数据库中的图像及其附带信息

mongodb - 如何使用动态组优化缓慢的 Mongo MapReduce

php - 如何检查数据库中出现的单词?