INNER CODE UNIT · JavaScript
Promise
mongodb-developer/nodejs-quickstart · changeStreams.js:65
return new Promise((resolve) => {
setTimeout(() => {
console.log("Closing the change stream");
changeStream.close();
resolve();
}, timeInMs)
})
};
/**
* Monitor listings in the listingsAndReviews collections for changes
* This function uses the on() function from the EventEmitter class to monitor changes
* @param {MongoClient} client A MongoClient that is connected to a cluster with the sample_airbnb database
* @param {Number} timeInMs The amount of time in ms to monitor listings
* @param {Object} pipeline An aggregation pipeline that determines which change events should be output to the console
*/
async function monitorListingsUsingEventEmitter(client, timeInMs = 60000, pipeline = []) {
const collection = client.db("sample_airbnb").collection("listingsAndReviews");