Questions tagged with Amazon DocumentDB

Content language: English

Sort by most recent

Browse through the questions and answers listed below or filter and sort to narrow down your results.

Error in connecting to document DB intermittently

Hi, I am facing the below exception intermittently. I am using the connection as below. “errorMessage”:“MongoTimeoutError: Server selection timed out after 30000 ms”,“reason”:{“errorType”:“MongoTimeoutError”,“errorMessage”:“Server selection timed out after 30000 ms”,“name”:“MongoTimeoutError”,“stack”:\[“MongoTimeoutError: Server selection timed out after 30000 ms”," at Timeout.setTimeout \[as _onTimeout] (/var/task/node_modules/mongodb/lib/core/sdam/server_selection.js:308:9)"," at ontimeout (timers.js:436:11)"," at tryOnTimeout (timers.js:300:5)"," at listOnTimeout (timers.js:263:5)"," at Timer.processTimers (timers.js:223:10)"]},“promise”:{},“stack”:\[“Runtime.UnhandledPromiseRejection: MongoTimeoutError: Server selection timed out after 30000 ms”," at process.on (/var/runtime/index.js:37:15)"," at process.emit (events.js:198:13)"," at process.EventEmitter.emit (domain.js:448:20)"," at emitPromiseRejectionWarnings (internal/process/promises.js:140:18)"," at process._tickCallback (internal/process/next_tick.js:69:34)"]} let connectionString = `mongodb://${data.username}:${data.password}@${clusterEndpoint}:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0`; return new Promise((resolve, reject) => { mongodb.connect(connectionString, { useUnifiedTopology: true }, (err, res) => { if (err) { reject(err); } else { resolve(res); } }) });
2
answers
0
votes
680
views
asked 2 years ago

Mongoose attempting to connect to instance instead of just cluster endpoint

We have our documentdb instance in a private VPC so use a bastion with port forwarding. I have the cluster endpoint setup in my SSH config and am able to connect via mongo shell: ``` $ mongo --ssl --host localhost:27018 --sslCAFile rds-combined-ca-bundle.pem --sslAllowInvalidHostnames MongoDB shell version v3.6.3 connecting to: mongodb://localhost:27018/ 2020-07-15T16:14:11.063-0400 D NETWORK [thread1] creating new connection to:localhost:27018 2020-07-15T16:14:11.266-0400 W NETWORK [thread1] The server certificate does not match the host name. Hostname: localhost does not match SAN(s): <information redacted> 2020-07-15T16:14:11.266-0400 D NETWORK [thread1] connected to server localhost:27018 (127.0.0.1) 2020-07-15T16:14:11.296-0400 D NETWORK [thread1] connected connection! MongoDB server version: 3.6.0 rs0:PRIMARY> ``` But when I try connecting via mongoose programmatically it attempts to connect to the instance directly instead of just the cluster endpoint. With useUnifiedTopology enabled: ``` const connOpts = { replicaSet: 'rs0', readPreference: 'secondaryPreferred', loggerLevel: 'debug' ha: false, connectWithNoPrimary: true, useNewUrlParser: true, useUnifiedTopology: true } mongoose.createConnection('mongodb://localhost:27018/mydb', connOpts) MongooseServerSelectionError: connection timed out reason: TopologyDescription { type: 'ReplicaSetNoPrimary', setName: 'rs0', maxSetVersion: null, maxElectionId: null, servers: Map { 'mydocdb-inst-1.[id redacted].[region redacted].docdb.amazonaws.com:27017' => [ServerDescription] }, stale: false, compatible: true, compatibilityError: null, logicalSessionTimeoutMinutes: null, heartbeatFrequencyMS: 10000, localThresholdMS: 15, commonWireVersion: 6 } ``` With useUnifiedTopology disabled: ``` const connOpts = { replicaSet: 'rs0', readPreference: 'secondaryPreferred', loggerLevel: 'debug' ha: false, connectWithNoPrimary: true, useNewUrlParser: true, useUnifiedTopology: false } mongoose.createConnection('mongodb://localhost:27018/mydb', connOpts) At the end of the debug output: [INFO-Server:9749] 1595262374081 server mydocdb-inst-1.[id redacted].[region redacted].docdb.amazonaws.com:27017 fired event error out with message {"name":"MongoNetworkError"} { type: 'info', message: 'server mydocdb-inst-1.[id redacted].[region redacted].docdb.amazonaws.com:27017 fired event error out with message {"name":"MongoNetworkError"}', className: 'Server', pid: 9749, date: 1595262374081 } ``` Is this due to some change in later versions of mongoose or the mongodb driver that aren't backwards compatible with mongodb 3.6.x / documentdb? Anyone on a specific version of mongoose and have it working without needing to connect directly to the instances? Thanks
3
answers
0
votes
400
views
asked 2 years ago
3
answers
0
votes
180
views
asked 3 years ago