Kizspy | Question: 8
(Choose 2 answers)
Consider the following code snippet for connecting to a MongoDB server. Identify the parts responsible for importing the MongoClient class and connecting to the server.
const { MongoClient } = require('mongodb');
const url = 'mongodb://localhost:27017';
const dbName = 'mydatabase';const client = new MongoClient(url);
async function run() {
try {
await client.connect();
console.log("Connected correctly to server");
const db = client.db(dbName);
} finally {
await client.close();}
run().catch(console.dir);
A. const { MongoClient } = require('mongodb'); is responsible for importing the MongoClient class.
B. const url = 'mongodb://localhost:27017'; is responsible for setting the database name.
C. await client.connect(); is responsible for connecting to the MongoDB server.
D. const db = client.db(dbName); is responsible for closing the connection to the MongoDB server.
FUOVER