Skip to content

Instantly share code, notes, and snippets.

@prashanthmadi
Last active February 18, 2022 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prashanthmadi/677dfede427806f96433064e91a3c2ac to your computer and use it in GitHub Desktop.
Save prashanthmadi/677dfede427806f96433064e91a3c2ac to your computer and use it in GitHub Desktop.
const { MongoClient } = require("mongodb");
var ReadPreference = require('mongodb').ReadPreference
// Replace the following with your MongoDB deployment's connection
// string.
const uri =
"mongodb://prmongotest:XSXz98HsbkOGyQN1SNnjilJKf5eDWDMXpJIvus8441jiiROq1WO86P84enVHw2izDtRTVndUev2l6hDX4VW6Tw==@prmongotest.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@prmongotest@";
const client = new MongoClient(uri, { monitorCommands:true });
// Replace <event name> with the name of the event you are subscribing to.
const eventName = "commandStarted";
client.on(eventName, event => {
// console.log(`received ${eventName}: ${JSON.stringify(event, null, 2)}`);
if(event.command.hasOwnProperty("find"))
console.log(JSON.stringify(event));
});
async function run() {
try {
await client.connect();
// Establish and verify connection
const findResult = await client.db("scheduler").collection("dataplane",{readPreference: ReadPreference.SECONDARY_PREFERRED}).find({}).toArray();
// console.log('Found documents =>', findResult);
// console.log("Connected successfully");
} finally {
// Ensures that the client will close when you finish/error
await client.close();
}
}
// run().catch(console.dir);
setInterval(function(){
run().catch(console.dir);
}, 10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment