twoh / twoh_mongodb_driver
Extends TYPO3 to support 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
Table of contents
General info
Extends TYPO3 to support MongoDB.
Getting started
Prerequisites
What things you need to install the software.
- PHP ^8.0
- composer ^2
- TYPO3 ^12
Setup
- Install Extension via Composer or FTP!
- Activate Extension
Configure Connection
Add Driver Connection Settings below to your config/system/settings.php
or 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'),
];
Call ConnectionPool
You can access the ConnectionPool Object and carry out your queries using the following line of code.
namespace: TWOH\TwohMongodbDriver\Adapter\MongodbConnectionPoolAdapter
$mongodbConnectionPoolAdapter = GeneralUtility::makeInstance(MongodbConnectionPoolAdapter::class);
$mongodbConnectionPoolAdapter->getConnectionPool()->selectDocuments(
$collectionName,
$filter,
$options
);
Example
The Example below shows how you can take a MongoDB call and return the output into your view:
/**
* @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');
}
Charts
We integrate our charts via chartjs.org: Chart JS Org
ConnectionPool Functions
Authors
- Andreas Reichel - Initial work
- Andreas Reichel - Bug fixes
- Andreas Reichel - Feature development