我在MongoDB中保存了一个嵌套文档,我想把它全部取出来,因为我知道ID
我可以选择一些类似的字段
public function actionFetchId()
{
$data = json_decode(file_get_contents("php://input"), TRUE);
$recordid = (string)$data['dh'];
$collection = Yii::$app->mongodb->getCollection('properties');
//Create Properties List Object
$basic_info_query = new Query;
$basic_info_query->select(['finalize'])
->from('properties')
->where(['_id' => $recordid]);
$rows = $basic_info_query->all();
return json_encode($recordid);
}
我可以在这里组装我想取的字段
$basic_info_query->select(['finalize','basic_info'])
但是,我想获取文档中的所有字段。如何在Yii2 Mongo中获取SQLselect * from properties
中的所有文档字段?
我能够像这个一样获取整个文档
public function actionFetchId()
{
$data = json_decode(file_get_contents("php://input"), TRUE);
$recordid = (string)$data['dh'];
$collection = Yii::$app->mongodb->getCollection('properties');
//Create Properties List Object
$fetch_all = new Query;
$fetch_all->from('properties')
->where(['_id' => $recordid]);
$rows = $fetch_all->all();
return json_encode($rows);
}