I have written the code to connect the database with node js with no mistakes and tried to execute the code but the error I have got is unable to understand, I have tried every solution that has been posted on youtube and google but none of them have helped me
I also reinstalled the MongoDB several times still getting the same problem

 const {MongoClient}=require('mongodb');
 const url='mongodb://localhost:27017';
 const database='local'
 const client=new MongoClient(url);

 async function getData()
     let result=await client.connect();
     let db=result.db(database);
     let collection=db.collection('startup_log');
     let response=await collection.find({}).toArray();

‘mongo’ is not recognized as an internal or external command,
operable program or batch file.
I am getting this when I have tried to check the version of MongoDB through cmd even the path in the system variable is clear
can anyone give the solution for it

The mongo command line tool is no longer installed with version 6.0 of MongoDB. If you used an installer it may have installed mongosh which is the newer replacement tool. If you don’t have mongosh, you can download it.

As for the error you’re getting, it looks like your app is trying to connect over IPv6 address. Change your connection code from

const url='mongodb://localhost:27017'


const url='mongodb://'

That should hopefully help resolve that issue.

it’s working . Thank you very much for your help sir

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.