I am new to mongoDB and nodejs i created a simple database and tried to connected to my nodejs but i get this error
**MongoServerSelectionError: connect ECONNREFUSED ::1:27017 at Timeout._onTimeout (C:\Users\Solutions\Desktop\MongoDB\node_modules\mongodb\lib\sdam\topology.js:312:38) at listOnTimeout (node:internal/timers:568:17) at processTimers (node:internal/timers:510:7) { reason: TopologyDescription { type: 'Unknown', **
MongoDB is running in my pc i can type mongodb commands i checked in task manager it is running everything looks fine but i can not connect it
this is my nodejs code
const url= 'mongodb://localhost:27017';
const databaseName='e-comm'
const client= new MongoClient(url);
async function getData()
{
let result = await client.connect();
db = result.db(databaseName);
collection = db.collection('products');
let data = await collection.find({}).toArray();
console.log(data)
}
getData();```
you need to add const { MongoClient } = require('mongodb'); in your code and also pass {useUnifiedTopology: true,useNewUrlParser: true} in MongoClient Constructure after url parameter as a best practice