PHP code example of lvinkim / mongo-oplog

1. Go to this page and download the library: Download lvinkim/mongo-oplog 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/ */

    

lvinkim / mongo-oplog example snippets



use Lvinkim\MongoOplog\Tail;
use MongoDB\Driver\Manager;

// 实现 HandlerInterface 接口

class Handler implements HandlerInterface
{
    public function handle($document): bool
    {
        var_dump($document);
        return true;
    }
}

// 运行 

$serverDns = 'mongodb://docker.for.mac.localhost';
$manager = new Manager($serverDns);
$tail = new Tail($manager);

$handler = new Handler();
$tail->pushHandler($handler);

$filter = [
    'ts' => ['$gte' => new \MongoDB\BSON\Timestamp(1, time())],
    'ns' => 'test.user',
];

$tail->run($filter);