2

I am trying to connect to my atlas cluster using connect() method and getting error as "No Primary Detected".

Here are the steps i performed:

  1. Run the mongo shell from command prompt.
  2. Execute load(); by passing the script file name.

File contains below script:

var url = "mongodb://leeban-m001-shard-00-00-sqjjv.mongodb.net:27017,leeban-m001-shard-00-01-sqjjv.mongodb.net:27017,leeban-m001-shard-00-02-sqjjv.mongodb.net:27017/test?replicaSet=Leeban-M001-shard-0";
var userName="mongo-m001";
var password="******";

var database = connect(url, userName, password);

When I execute the command through shell (without using connect method.) I am able to connect to Atlas cluster.

Is connect() method will work to connect to mongodb clusters?

1
  • This is common for users who have not whitelisted their IP address. Please review the Security/IP Whitelists for your inbound client IP.
    – Jay Gordon
    Commented Sep 25, 2017 at 18:03

1 Answer 1

1

Can you try adding the authMechanism=SCRAM-SHA-1 option to your connection string?

The following script should work:

var url = "mongodb://leeban-m001-shard-00-00-sqjjv.mongodb.net:27017,leeban-m001-shard-00-01-sqjjv.mongodb.net:27017,leeban-m001-shard-00-02-sqjjv.mongodb.net:27017/test?replicaSet=Leeban-M001-shard-0&authMechanism=SCRAM-SHA-1";
var userName="mongo-m001";
var password="******";

var database = connect(url, userName, password);

I hope this helps!

Not the answer you're looking for? Browse other questions tagged or ask your own question.