No way to avoid ReplicaSetNoPrimary errors

i have a similar issue.
I’ve built an app with React for the frontend and Node.js for the backend, linked to a MongoDB cluster using Mongoose. I’m working with two branches: main and dev. I’ve noticed that when I do a new deploy (prod or dev), the app stops working and shows a server error. To fix this, I have to redeploy the branch. Each branch has its own environment variables (preview and prod) and main is linked to a mongodb prod database, dev to another mongodb dev database so apparently each branch has the right configuration. I get these kind of messages:

Failed to connect to MongoDB 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: ht/docs/atlas/security-whitelist/
at _handleConnectionErrors (/var/task/backend/node_modules/mongo09:11)
at NativeConnection.openUri (/var/task/backend/node_modules/mongoose/lis:860:11) {
reason: TopologyDescription {
type: ‘ReplicaSetNoPrimary’,
servers: Map(3) {
cluster0-shard-00-01.xxx.mongodb.net:27017’ => [ServerDescription],
cluster0-shard-00-02.xxx.mongodb.net:27017’ => [ServerDescription],
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: ‘atlas-xxxx-shard-0’,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}