Mongoose can't connect to mongodb 4.4.4 replica set inside a docker container
See original GitHub issueWhat is the expected behavior? Mongoose should be able to connect to local replica set inside a docker container. When I updated my mongoose version from 5.x to 6.0.5 mongoose stopped connecting to my local replica set. When I tried to connecting to a normal non replica set container it worked fine. I reverted back my mongoose version to 5.13.9 and it connected to the RS with no problem. Here’s the stack trace for the error trying to connect with version 6.0.5, mongodb version 4.4.4 and node 14.17.0
MongooseServerSelectionError: getaddrinfo ENOTFOUND 508be0425c52
at NativeConnection.Connection.openUri (/projectPath/node_modules/mongoose/lib/connection.js:798:32)
at /projectPath/node_modules/mongoose/lib/index.js:330:10
at promiseOrCallback (/projectPath/node_modules/mongoose/lib/helpers/promiseOrCallback.js:10:12)
at Mongoose._promiseOrCallback (/projectPath/node_modules/mongoose/lib/index.js:1151:10)
at Mongoose.connect (/projectPath/node_modules/mongoose/lib/index.js:329:20)
at Object.<anonymous> (/projectPath/app.js:25:10)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Module.require (internal/modules/cjs/loader.js:957:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/projectPath/bin/www:7:11)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
servers: Map(1) { '508be0425c52:27017' => [ServerDescription] },
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: 'rs0',
maxSetVersion: 2,
maxElectionId: new ObjectId("7fffffff0000000000000009"),
commonWireVersion: 9,
logicalSessionTimeoutMinutes: undefined
}
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:6
Top Results From Across the Web
MongoDB Replica Docker: Cannot connect on replica, only ...
I cannot login to replica set, but can on individual nodes. For example, I create a new document in primary replica and without...
Read more >MongoDB replica set, error when connecting from mongoose ...
I have another single Mongo container which is running on 27017 0.0.0.0:27017->27017/tcp docker_mongodb bellow are replicaSet ports 0.0.0.0: ...
Read more >Docker container unable to connect to MongoDB Replica set
1 Answer 1 · Make sure the hostnames used in your replica set config ( Mongo1 , Mongo2 , Mongo3 ) can be...
Read more >Creating a MongoDB Replica Set Using Docker
Now that we have all our Mongo instances up and running, let's add them to a replica set. Connect to the Mongo shell...
Read more >Using MongoDB with Docker - Earthly Blog
For development, it is better to connect to an instance of MongoDB running inside a Docker container locally (instead of a cloud-hosted instance) ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@omarwaleed Use
directConnection: true
while connecting viamongoose.connect()
Driver Option MongoDB Docs@Vinayjinugu-gep https://mongoosejs.com/docs/connections.html#replicaset-hostnames