Skip to content

Instantly share code, notes, and snippets.

@prashanthmadi
Last active February 17, 2022 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save prashanthmadi/8e837720a7ece5b1ec1b47b348ff0710 to your computer and use it in GitHub Desktop.
Save prashanthmadi/8e837720a7ece5b1ec1b47b348ff0710 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://cosmomongo13:==@cosmomongo13.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@cosmomongo13@";
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)}`);
});
async function run() {
try {
await client.connect();
// Establish and verify connection
const findResult = await client.db("scheduler").collection("dataplane",{readPreference: ReadPreference.SECONDARY}).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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment