Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP mongodb上使用不同的操作速度较慢_Php_Performance_Mongodb - Fatal编程技术网

在PHP mongodb上使用不同的操作速度较慢

在PHP mongodb上使用不同的操作速度较慢,php,performance,mongodb,Php,Performance,Mongodb,我正在使用mongoDB来存储用户的日志。在我的实时报告中,我需要统计特定类型中表的不同用户。开始时,它运行得很快,但当桌子变大时,速度会变慢 以下是我使用的代码: $connection = new MongoClient(); $result = $collection->distinct('user', array('type' => $type, 'ctime' => array('$gte' => $start))); $total = count($resul

我正在使用mongoDB来存储用户的日志。在我的实时报告中,我需要统计特定类型中表的不同用户。开始时,它运行得很快,但当桌子变大时,速度会变慢

以下是我使用的代码:

$connection = new MongoClient();
$result = $collection->distinct('user', array('type' => $type, 'ctime' => array('$gte' => $start)));
$total = count($result);
$total
是唯一用户的总数

有人能建议我如何改进查询以获得更好的性能吗?
非常感谢。

使用
$collection->ensureIndex(数组('user'=>1))
在用户字段上创建索引。

您的文档结构在哪里?另外,在shell版本中键入查询,这样人们可以更快地测试它。文档结构是:array('user','type','ctime')这不是一个文档结构,我们的意思是你的行看起来像什么,还有你区分了多少行对不起,我用PHP创建了行,行看起来像{“allen”,“type1”,1378375980}{“allen”,“type1”,1378375980}{“john”,“type2”,1378895340}在
用户上有索引吗?你区分了多少行?