Trying to connect mongodb with nodejs

const {MongoClient} = require('mongodb');
const uri = "mongodb://localhost:27017";
const database = 'ecommerce'

const client = new MongoClient(uri);

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




ECONNREFUSED indicates that there is not server listening at the given address/port.

Make sure mongod is running and listening on the appropriate address and port.

Try with rather than localhost. The part of the error ::1:27017 seems to indicate that localhost resolve to IPv6.


Thanku so muchhhhhhhh sir

1 Like

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