我有一个从 MongoDB 收集数据并打印出来的 PHP 脚本。一些选项是从$_POST
supergoblal 收集的。一切正常,但我不能限制使用数组返回的字段。
$results = $db->$table->find($param); //This line works and returns all fields
$results = $db->$table->find($param, array('Descripción','Ocurrencias relacionadas'));//This line works and limit the returned fields to the ones specified.
以下代码构造一个数组以用作字段限制器参数:
$fields=implode(',', $_POST[field]);
$fd = array($fields);
print_r($fd)
显示:
Array ( [0] => 'Descripción','Ocurrencias relacionadas' )
$results = $db->$table->find($param,$fd);` //This line works and returns all documents but only _id field.
有任何想法吗?快把我逼疯了!提前致谢。