xxxxxxxxxx
mongodb://myDBReader:D1fficultP%40ssw0rd@mongodb0.example.com:27017/?authSource=admin
xxxxxxxxxx
// Import the required MongoDB driver
const MongoClient = require('mongodb').MongoClient;
// Connection URL for the local MongoDB instance
const url = 'mongodb://localhost:27017';
// Creating a new MongoClient instance
const client = new MongoClient(url, { useNewUrlParser: true });
// Connect to the MongoDB server
client.connect(function(err) {
if (err) {
console.error('Error connecting to MongoDB:', err);
return;
}
console.log('Connected successfully to MongoDB');
// Perform further operations on the database
// Close the connection when done
client.close();
});