我有一些包含大量数据的文档,但在特定页面查询时不需要这些数据,因此我想加快请求速度。当我在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;