Node JS Tutorial in Hindi #60 Connect MongoDB Atlas with Node.js

Connect Mongodb Atlas with Node js


Points of this video

  1. Check Connect method.
  2. Setup connect in node js.
  3. Write code for connection.
  4. Test connection and Data
  5. Interview Questions Notes,
  6. Code and playlist.


code of index.js file

import { MongoClient } from "mongodb";

const url="mongodb+srv://webanilsidhu:GoogleTest@cluster0.dqwwk5n.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0";
const database="school";
const collection="student";
const client= new MongoClient(url);
client.connect().then(()=>{
console.log(".......connect..........");
})

async function dbConnection(){
const db= client.db(database)
const collectResult = db.collection(collection);
const result = await collectResult.find().toArray();
console.log(result);
}

dbConnection()

Github Link :- https://github.com/anil-sidhu/node-express-mongodb/tree/mongodb-atlas