PHP code example of madewithlove / broadway-mongodb

1. Go to this page and download the library: Download madewithlove/broadway-mongodb library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

madewithlove / broadway-mongodb example snippets


$factory = new MongoDBClientFactory();
$client = $factory->create(['database' => 'foobar']);

$factory = new MongoDBClientFactory();
$client = $factory->create([
     'database' => 'foobar',
     'host' => 'my_host',
     'port' => 3000,
]);

// Or alternatively

$client = $factory->create([
     'database' => 'foobar',
     'host' => 'my_host:3000',
]);

$factory = new MongoDBClientFactory();
$client = $factory->create([
     'database' => 'foobar',
     'host' => ['my_host_1', 'my_host_2'],
]);

$factory = new MongoDBClientFactory();
$client = $factory->create([
     'database' => 'foobar',
     'username' => 'foo',
     'password' => 'bar',
]);

$factory = new MongoDBClientFactory();
$client = $factory->create([
     'dsn' => 'mongodb://foo:200/foo',
]);


 $mongDBClientFactory = new MongoDBClientFactory();
 $client = $factory->create(['database' => 'testing']);

 $factory = new ReadModel\Factory(
    new SimpleInterfaceSerializer(),
    $client->selectDatabase('testing')
);

// 'my_projection' is the collection that will be used.
$repository = $factory->create('my_projector');

// If you have a custom read model repository you can use the factory to create your own instances:
$repository = $factory->create('my_projector', MyReadModelRepository::class);