Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
why cant I connect mongodb to nodejs from localhost?

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();```
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!