从mongodb到php输入Map的最佳方法是什么?

时间:2016-07-14 09:09:53

标签: php mongodb php-7

我已将PHP7连接到MongoDB,数据是在bson对象中获取的 MongoDB\BSON\ObjectID

使用mongo-php-library tutorial,我能够映射一些返回的字段,但我们在教程中看到“{Persistable Classes”,如ObjectIDUTCDateTime

解决它我构建了以下小方法,它将Persistable Classes数据更改为字符串。我的问题是这样,这是将数据提供给我的PHP系统或更高级工具的正确方法(我的搜索无法找到)?

 /**
 * this function handels one returned document
*/
function normailze($result)
{
    foreach ($result as $key => $field) {
        if (is_object($field)) {

            $result[$key] = (string)$field;
        } else if (is_array($field)) {

            $result[$key] = $this->normailze($field);
        }
    }
    return $result;
}

0 个答案:

没有答案
相关问题