Last active
February 17, 2022 19:18
-
-
Save prashanthmadi/8e837720a7ece5b1ec1b47b348ff0710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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