private static function convertFromMongo(array $data)
    {
        // Move the Mongo _id field into an 'id' field.
        if (isset($data['_id'])) {
            $data['id'] = $data['_id'];
            unset($data['_id']);
        }

        foreach ($data as $name => &$value) {
            if (is_array($value)) {
                // Inner documents are converted too.
                $value = self::convertFromMongo($value);
            } elseif (is_object($value)) {
                switch (get_class($value)) {
                    case 'MongoId':
                        $value = $value->__toString();
                        break;
                    case 'MongoDate':
                        $value = new \DateTime('@' . $value->sec);
                        break;
                }
            }
        }

        return $data;
    }