【发布时间】:2016-09-30 18:21:18
【问题描述】:
我有一个包含大量数据的文档,我不需要在页面上进行特定查询,并且我想加快请求速度。当我从 mongo shell 执行以下查询时:
db.hosts.find({},{dmiSystem: 1, networkInterfaces: 1, lanPrint: 1, pduPorts: 1})"
mongo shell 几乎立即返回我要求的字段。当我使用 MongoDB\Client 从 PHP 执行相同的查询时,它需要大约 5 秒,就像我只是在没有任何参数的情况下运行 find() 一样。有任何想法吗?我的代码是:
$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->selectCollection("consoleServer", "hosts");
$rows = $collection->find(array(),array("_id" => 1, "dmiSystem" => 1,
"networkInterfaces" => 1, "lanPrint" => 1,
"pduPorts" => 1));
return $rows;
【问题讨论】:
标签: php mongodb projection