我正在尝试从PHP-MongoDB中排除_id字段result.below是我的PHP脚本。我可以添加到脚本中以从输出中排除_id。
<?php
try
{
$connection = new Mongo('mongodb://user:pass@xxxx.mlab.com:xxxxx/stats');
$database = $connection->selectDB('stats');
$collection = $database->selectCollection('stat');
}
catch(MongoConnectionException $e)
{
die("Failed to connect to database ".$e->getMessage());
}
$cursor = $collection->find();
echo json_encode(iterator_to_array($cursor));
?>
答案 0 :(得分:1)
添加: -
$cursor->fields(array('_id'=>false));
找到后......