mongoNetwork error when using replicaSet option in connecting #7165

@amiiy

Description

when connecting to another host MongoDB from application I used:

try { mongoose .connect( connectionString, { connectTimeoutMS: 4000, useNewUrlParser: true, replicaSet }, .then(() => mongoose.connection.db.admin().command({ setFeatureCompatibilityVersion: '4.0' })); } catch (error) { console.log('Mongodb Connection Error');

now when I want to connect to local database its fine and connect well. but when connectionsString changed to mongodb://172.116.12.8:27017/new for example it returns some error like below:

MongoNetworkError: failed to connect to server [localhost:27019] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27019]
    at Pool.<anonymous> (/home/xxx/Desktop/work/x-project-backend/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/server.js:562:11)
    at emitOne (events.js:116:13)
    at Pool.emit (events.js:211:7)
    at Connection.<anonymous> (/home/xxx/Desktop/work/x-project-backend/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:316:12)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at Connection.emit (events.js:214:7)

pay attention to its error log which say cannot connect to port 27019 which is another replica but i said to application to connection 27017 which is master.
i using the latest mongoose and mongodb with replicaSet option which are in same network.