Connect NodeJs with MongoDB local device




const {MongoClient} = require('mongodb');

const database =  'Class12';

const url = 'mongodb://0.0.0.0:27017';

const client = new MongoClient(url);

async function getdata(){
    let result = await client.connect();
    let db  =  result.db(database);
    let collection = db.collection('students');
    let response  = await collection.find({}).toArray();
    console.log(response);
}

getdata();

Comments

Popular posts from this blog

React Installation with Vite and Tailwind css (Steps to Installation)

Insert Data In mongoDb

Class methods as an alternative Constructor