1

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?

jsmith
  • 89
  • 1
  • 15
  • And of course you can connect to your RS (from command line) with 'mongo --host "dev-testserver-com/dev.testserver.com:27017,dev.testserver.com:27018,dev.testserver.com:27019" ua' -command? – JJussi Jun 03 '17 at 07:22
  • @JJussi Thats not what I am looking for. I am looking to specifically connect using NodeJS. – jsmith Jun 06 '17 at 18:49
  • I asked tuhat just to check tuhat your replucaset is actually working and there is no connection problem. So many times I have seen that – JJussi Jun 06 '17 at 19:39

1 Answers1

0

Looks like there is a problem in your server(s). You need to get on the server(s) and run rs.status() to find out the state of your replica set, and each server's logs to find out if and why one or more has stopped or become disconnected.

Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56