twoh/twoh_mongodb_driver

扩展TYPO3以支持MongoDB。

安装: 2

依赖项: 0

建议者: 0

安全: 0

星星: 0

分支: 0

类型:typo3-cms-extension

1.0.0 2024-03-16 09:05 UTC

This package is auto-updated.

Last update: 2024-09-16 09:24:42 UTC


README

目录

一般信息

扩展TYPO3以支持MongoDB。

入门指南

先决条件

您需要安装以下软件。

  • PHP ^8.0
  • composer ^2
  • TYPO3 ^12

设置

  • 通过Composer或FTP安装扩展!
  • 激活扩展

配置连接

将以下驱动连接设置添加到您的 config/system/settings.phpconfig/system/additional.php

$GLOBALS['TYPO3_CONF_VARS']['DRIVER']['MongoDB'] = [
    'host' => getenv('TOOL_DB_HOST'),
    'dbname' => getenv('TOOL_DB_DATABASE'),
    'user' => getenv('TOOL_DB_USERNAME'),
    'password' => getenv('TOOL_DB_PASSWORD'),
    'port' => getenv('TOOL_DB_PORT'),
];

调用连接池

您可以使用以下代码行访问连接池对象并执行查询。

命名空间: TWOH\TwohMongodbDriver\Adapter\MongodbConnectionPoolAdapter

$mongodbConnectionPoolAdapter = GeneralUtility::makeInstance(MongodbConnectionPoolAdapter::class);
$mongodbConnectionPoolAdapter->getConnectionPool()->selectDocuments(
    $collectionName, 
    $filter,
    $options
);
示例

以下示例展示了如何将MongoDB调用结果返回到您的视图中。

/**
 * @var MongodbConnectionPoolAdapter 
 */
protected MongodbConnectionPoolAdapter $mongodbConnectionPoolAdapter;

/**
 * @param ModuleTemplateFactory $moduleTemplateFactory
 * @param IconFactory $iconFactory
 */
public function __construct(
    protected MongodbConnectionPoolAdapter $mongodbConnectionPoolAdapter
) {
}

/**
 * @param ServerRequestInterface $request
 * @param ModuleTemplate $view
 * @return ResponseInterface
*/
public function indexAction(
    ServerRequestInterface $request,
    ModuleTemplate $view
): ResponseInterface
{
    $view->assignMultiple(
        [
            'users' => $this->mongodbConnectionPoolAdapter->getConnectionPool()->selectDocuments(
                'user',
                [
                    'uuid' => 'user1',
                ],
                [
                    'limit' => 5,
                    'projection' => [
                        'uuid' => 1,
                        'username' => 1,
                        'email' => 1,
                        'name' => 1,
                        'pageInteractions' => 1,
                    ],
                ],
            )
        ]
    );
    return $view->renderResponse('AdminModule/Index');
}

图表

我们通过chartjs.org集成图表: Chart JS Org

连接池函数

连接池函数

作者

  • Andreas Reichel - 初始工作
  • Andreas Reichel - 错误修复
  • Andreas Reichel - 功能开发