twoh / twoh_mongodb_driver
扩展TYPO3以支持MongoDB。
1.0.0
2024-03-16 09:05 UTC
Requires
- php: >=8.0
- ext-mongodb: *
- mongodb/mongodb: ^1.17
- typo3/cms-core: ^12.4
Requires (Dev)
- roave/security-advisories: dev-latest
README
目录
一般信息
扩展TYPO3以支持MongoDB。
入门指南
先决条件
您需要安装以下软件。
- PHP ^8.0
- composer ^2
- TYPO3 ^12
设置
- 通过Composer或FTP安装扩展!
- 激活扩展
配置连接
将以下驱动连接设置添加到您的 config/system/settings.php
或 config/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 - 功能开发