-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.0.5
-
Component/s: Lambda
-
Environment:NodeJS 4.9.1, 8.10.0.
MongoDB 3.4.14
Mongo Atlas (AWS us-east-1)
-
(copied to CRM)
-
Empty show more show less
When making a mongodb connection with readPreference=secondary, the connection hangs and never succeeds. It also doesn't return an error.
Here's some code to reproduce it:
// setup const MongoClient = require('mongodb').MongoClient; // sample connection string const MONGO_URL = 'mongodb://dev-api:PASSWORD@testing-dev-shard-00-00-rbwsc.mongodb.net:27017,testing-dev-shard-00-01-rbwsc.mongodb.net:27017,testing-dev-shard-00-02-rbwsc.mongodb.net:27017/testingdb?ssl=true&replicaSet=testing-dev-shard-0&authSource=admin'
Working example:
// Default read preference MongoClient.connect(MONGO_URL).then(function(client) { console.log(client); process.exit(); }).catch(function(err) { console.log(err); process.exit(); });
Not working example:
// Secondary read preference MongoClient.connect(MONGO_URL, { readPreference: 'secondary' }).then(function(client) { console.log(client); // never reaches here process.exit(); }).catch(function(err) { console.log(err); // never reaches here process.exit(); });