Unable to connect to ReplicSet, received `MongoServerSelectionError: ECONNREFUSED 127.0.0.1:27018` message

I am trying to connect to docker (Windows) replicaSet which has 5 nodes.
I am using node.js, I have tried with mongoose and Mongoclient but received

MongoServerSelectionError: ECONNREFUSED 127.0.0.1:27018

in both cases.

Any idea why I am receiving this mesage.

Mongoose configuration

const DB_URI = 'mongodb://rs0:27018,rs1:27019,rs2:27020,rs3:27021,rs4:27022/admin?replicaSet=rsnmbp mongoose.connect(DB_URI, { serverSelectionTimeoutMS: 5000 }).then((result) =>console.log ("connected to database")) .catch((err) =>console.log (err.reason))

Mongoclient configuration

MongoClient.connect("mongodb://rs0:27018,rs1:27019,rs2:27020,rs3:27021,rs4:27022/", function(err, db) { test.equal(null, err); test.ok(db != null); })

Docker compose file

version: '3'

services:

  rs0:
    image: mongo:4.4
    ports:
      - "27018:27017"
    command: mongod --replSet rsnmbp
    volumes:
      - rs0_data:/data/db
      - ./nmbprsdata0:/nmbpdata

  rs1:
    image: mongo:4.4
    ports:
      - "27019:27017"
    command: mongod --replSet rsnmbp
    volumes:
      - rs1_data:/data/db
      - ./nmbprsdata1:/nmbpdata

  rs2:
    image: mongo:4.4
    ports:
      - "27020:27017"
    command: mongod --replSet rsnmbp
    volumes:
      - rs2_data:/data/db
      - ./nmbprsdata2:/nmbpdata
      
  rs3:
    image: mongo:4.4
    ports:
      - "27021:27017"
    command: mongod --replSet rsnmbp
    volumes:
      - rs3_data:/data/db
      - ./nmbprsdata3:/nmbpdata
      
  rs4:
    image: mongo:4.4
    ports:
      - "27022:27017"
    command: mongod --replSet rsnmbp
    volumes:
      - rs4_data:/data/db
      - ./nmbprsdata4:/nmbpdata
      
   

volumes:
  rs0_data:
  rs1_data:
  rs2_data:
  rs3_data:
  rs4_data:

ReplicaSet config

rsconf = { 
  _id: "rsnmbp", 
  members: [ 
    { 
      _id: 0, 
      host: "rs0:27017" 
    }, 
    { 
      _id: 1, 
      host: "rs1:27017" 
    }, 
    { 
      _id: 2, 
      host: "rs2:27017" 
    },
    { 
      _id: 3, 
      host: "rs3:27017" 
    },
    { 
      _id: 4, 
      host: "rs4:27017" 
    },
  ] 
} 
rs.initiate(rsconf)