Mongodb atlas replica is not connecting after failover

hi Guys,

Need help with MonoDB atlas connection issue after failover to different replica.

As part of DR drill, I was doing test failover for MongoDB atlas , during test failover process , available secondary replica became primary but application is unable to reach MongoDB atlas.

Any thoughts\suggestion on this?

If you are using SRV type connect string it should detect the new primary and connect automatically
What type of connect string are you using in your app?

yes , using SRV type connection string in app.

Can you connect by shell using SRV string?

After failover , can not connect from shell as well.

What error message are you getting? Can’t connect is pretty vague and could be due to a lot of issues.

  1. Getting below error from app side-

GET /api/v1/languageConstant?locale=en-us - - ms - -
MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you’re trying to access the database from an IP that isn’t whitelisted. Make sure your current IP address is on your Atlas cluster’s IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
at Function.Model.$wrapCallback (/usr/src/app/node_modules/mongoose/lib/model.js:5087:32)
at /usr/src/app/node_modules/mongoose/lib/model.js:504:27
at /usr/src/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
at new Promise ()
at promiseOrCallback (/usr/src/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
at Mongoose._promiseOrCallback (/usr/src/app/node_modules/mongoose/lib/index.js:1149:10)
at model.Model.save (/usr/src/app/node_modules/mongoose/lib/model.js:503:35)
at exports.createApplicationLog (/usr/src/app/controllers/customLoggerV2Controller.js:9:35)
at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
at next (/usr/src/app/node_modules/express/lib/router/route.js:137:13)
at /usr/src/app/routes/customLoggerV2Routes.js:11:13
at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
at next (/usr/src/app/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/usr/src/app/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
at /usr/src/app/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:335:12)
at next (/usr/src/app/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/usr/src/app/node_modules/express/lib/router/index.js:174:3)
at router (/usr/src/app/node_modules/express/lib/router/index.js:47:12)
at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/usr/src/app/node_modules/express/lib/router/index.js:317:13) {
reason: TopologyDescription {
type: ‘ReplicaSetNoPrimary’,
setName: ‘atlas-11x95p-shard-0’,
maxSetVersion: 10,
maxElectionId: 7fffffff0000000000000041,
servers: Map(3) {
‘-pri.a4dcp.mongodb.net:27017’ => [ServerDescription],
‘-pri.a4dcp.mongodb.net:27017’ => [ServerDescription],
‘-pri.a4dcp.mongodb.net:27017’ => [ServerDescription]
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: 9
}
}

  1. Connection timeout error from MongoCompass\MongoShell.

Have you whitelisted your IP.If yes remove and add again.This fix worked for some people for connectivity issues after failover.
Also did you try to connect directly to new primary giving it’s address & port
Something blocking your connection.Coild be firewall/network issues

Entire Vnet is added through Peering . I didn’t try by directly connecting to the primary after failover.