twoh/twoh_mongodb_driver

Extends TYPO3 to support MongoDB.

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

Type:typo3-cms-extension

1.0.0 2024-03-16 09:05 UTC

This package is auto-updated.

Last update: 2024-04-16 08:26:19 UTC


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

ConnectionPool Functions

Authors

  • Andreas Reichel - Initial work
  • Andreas Reichel - Bug fixes
  • Andreas Reichel - Feature development