Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { MongoClient } = require('mongodb');
- async function listenToChanges() {
- const uri = 'mongodb://yourMongoDBURI';
- const client = new MongoClient(uri);
- try {
- await client.connect();
- const database = client.db('yourDatabase');
- const collection = database.collection('yourCollection');
- const changeStream = collection.watch();
- changeStream.on('change', (change) => {
- console.log('Change detected:', change);
- });
- } finally {
- // Keep the connection open to listen for changes
- }
- }
- listenToChanges().catch(console.error);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement