xp-forge / mongodb

MongoDB for the XP Framework
0 stars 0 forks source link

Change streams: Watch databases and collections for changes #15

Closed thekid closed 2 years ago

thekid commented 2 years ago

Implements #14 and adds change streams:

use com\mongodb\MongoConnection;
use util\cmd\Console;

$c= new MongoConnection($dsn);
$c->connect();

// Watch a collection
$cursor= $c->collection('dialog', 'entries')->watch();

// Watch a database
$cursor= $c->database('dialog')->watch();

// Watch all databases
$cursor= $c->watch();

foreach ($cursor as $change) {
  Console::writeLine('>> ', $change);
}