Problem Statement
How would you connect a MongoDB database to Node.js?
Explanation
To connect MongoDB with Node.js, use the official MongoDB driver or Mongoose. You create a client using MongoClient, provide the connection URL, and call `connect()`. Mongoose adds schema and validation features.
Code Solution
SolutionRead Only
const { MongoClient } = require('mongodb');
const uri = 'mongodb://localhost:27017';
const client = new MongoClient(uri);
await client.connect();
console.log('Connected to MongoDB');