Friday, 2 June 2017

Cannot connect to MongoDB via NodeJS - No primary found in replica set error

I am having difficulty connecting to MongoDB via NodeJS. The Mongo setup consists of a shared cluster.

The URL is below:

mongodb://dev.testserver.com:27017,dev.testserver.com:27018,dev.testserver.com:27019/ua?w=0&replicaSet=dev-testserver-com&readPreference=secondary&slaveOk=true

The code that I have is below:

    var MongoClient = require('mongodb').MongoClient;
MongoClient.connect(url, function(err db) {
  if(!err) {
    console.log("We are connected");
  }

  db.close();
});

The error that I keep getting is "MongoError: no primary found in replicaset".

Can someone please help?



via jsmith

No comments:

Post a Comment