Facing error while connecting to the server through NODE.js to MongoDB

C:\Users\sambit\OneDrive\Desktop\Fruitproject\node_modules\mongodb\lib\sdam\topology.js:278
                const timeoutError = new error_1.MongoServerSelectionError(`Server selection timed out after ${serverSelectionTimeoutMS} ms`, this.description);     
                                     ^

MongoServerSelectionError: connect ECONNREFUSED ::1:27017
    at Timeout._onTimeout (C:\Users\sambit\OneDrive\Desktop\Fruitproject\node_modules\mongodb\lib\sdam\topology.js:278:38)
    at listOnTimeout (node:internal/timers:568:17)
    at process.processTimers (node:internal/timers:511:7) {
  reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) {
      'localhost:27017' => ServerDescription {
        address: 'localhost:27017',
        type: 'Unknown',
        hosts: [],
        passives: [],
        arbiters: [],
        tags: {},
        minWireVersion: 0,
        maxWireVersion: 0,
        roundTripTime: -1,
        lastUpdateTime: 26216153,
        lastWriteDate: 0,
        error: MongoNetworkError: connect ECONNREFUSED ::1:27017
            at connectionFailureError (C:\Users\sambit\OneDrive\Desktop\Fruitproject\node_modules\mongodb\lib\cmap\connect.js:370:20)
            at Socket.<anonymous> (C:\Users\sambit\OneDrive\Desktop\Fruitproject\node_modules\mongodb\lib\cmap\connect.js:293:22)
            at Object.onceWrapper (node:events:627:26)
            at Socket.emit (node:events:512:28)
            at emitErrorNT (node:internal/streams/destroy:151:8)
            at emitErrorCloseNT (node:internal/streams/destroy:116:3)
            at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
          cause: Error: connect ECONNREFUSED ::1:27017
              at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
            errno: -4078,
            code: 'ECONNREFUSED',
            syscall: 'connect',
            address: '::1',
            port: 27017
          },
          [Symbol(errorLabels)]: Set(1) { 'ResetPool' }
        },
        topologyVersion: null,
        setName: null,
        setVersion: null,
        electionId: null,
        logicalSessionTimeoutMinutes: null,
        primary: null,
        me: null,
        '$clusterTime': null
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: null,
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined,
  [Symbol(errorLabels)]: Set(0) {}
}
~~~[quote="Sambit_Pradhan, post:1, topic:228709, full:true"]

C:\Users\sambit\OneDrive\Desktop\Fruitproject\node_modules\mongodb\lib\sdam\topology.js:278
const timeoutError = new error_1.MongoServerSelectionError(Server selection timed out after ${serverSelectionTimeoutMS} ms, this.description);
^

MongoServerSelectionError: connect ECONNREFUSED ::1:27017
at Timeout._onTimeout (C:\Users\sambit\OneDrive\Desktop\Fruitproject\node_modules\mongodb\lib\sdam\topology.js:278:38)
at listOnTimeout (node:internal/timers:568:17)
at process.processTimers (node:internal/timers:511:7) {
reason: TopologyDescription {
type: ‘Unknown’,
servers: Map(1) {
‘localhost:27017’ => ServerDescription {
address: ‘localhost:27017’,
type: ‘Unknown’,
hosts: ,
passives: ,
arbiters: ,
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 26216153,
lastWriteDate: 0,
error: MongoNetworkError: connect ECONNREFUSED ::1:27017
at connectionFailureError (C:\Users\sambit\OneDrive\Desktop\Fruitproject\node_modules\mongodb\lib\cmap\connect.js:370:20)
at Socket. (C:\Users\sambit\OneDrive\Desktop\Fruitproject\node_modules\mongodb\lib\cmap\connect.js:293:22)
at Object.onceWrapper (node:events:627:26)
at Socket.emit (node:events:512:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
cause: Error: connect ECONNREFUSED ::1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
errno: -4078,
code: ‘ECONNREFUSED’,
syscall: ‘connect’,
address: ‘::1’,
port: 27017
},
[Symbol(errorLabels)]: Set(1) { ‘ResetPool’ }
},
topologyVersion: null,
setName: null,
setVersion: null,
electionId: null,
logicalSessionTimeoutMinutes: null,
primary: null,
me: null,
‘$clusterTime’: null
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
}

[/quote]

Hello, all I'm new to Mongo so I’ll do my best to provide as many details as possible to solve my issue.
I am using Windows 11 OPS and installed MongoDB 6.0 and Launched the db with `mongod --dbpath ~/data/db`.
My issue is trying to connect using the official mongodb 6.0 node package . I’ve stripped down the code only trying to connect() to the server of MONGODB.

I have written code in my Editior
const MongoClient = require(‘mongodb’).MongoClient;
const assert = require(‘assert’);

const url = ‘mongodb://127.0.0.1:27017’;

const dbName = ‘fruitsDB’;

const Client = new MongoClient(url,{UseNewUrlParser:true});

Client.connect(function(err){
** assert.equal(null,err);**
** console.log(“Connected successfullty to server”);**

** const db = Client.db(dbName);**

** Client.close();**
})