0

EDIT:

Not sure what I've done differently (again, these are my first steps with all of this), but now I don't get the error message I got before. Instead though, it just tries to make the connection and I get

Server selection timed out after 30000 ms

After some time.

ORIGINAL:

I am new to using MongoDB - currently taking a back end course online.

It seems that Compass has changed their interface for adding a new connection, lately, and maybe some business logic, because all guides I find use the previous one.

Specifically, when adding a new connection, in the guides I read, they leave Replica Set Name empty. When I try to do that, I get an error saying Incomplete key value pair for option.

I tried just calling it localhost and it "works", but I don't see any of my DBs. If I connect with Robo 3t I can see them.

Is it a wrong Replica Set Name that's preventing me from deeing the DBs? Or am I doing something else wrong?

My settings for when trying to connect are:

Hostname : `localhost`
port : 27017
SRV record : I leave it off
Authentication : None
Replica Set Name : localhost
Read preferences : Primary
SSl : none
SSL tunnel : None
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Tsabary
  • 3,119
  • 2
  • 24
  • 66

2 Answers2

1

It appears that Compass requires a replica set name to be specified, based on the following message I get when I specify a single host which happens to be a secondary:

An error occurred while loading navigation: 'not master and slaveOk=false': It is recommended to change your read preference in the connection dialog to Primary Preferred or Secondary Preferred or provide a replica set name for a full topology connection.

"Server selection timed out" can mean different things:

  • There isn't a database running.
  • The database is running but you entered the wrong port number.
  • Compass attempted to perform a specific operation which required a certain server type (e.g. a primary or a secondary). The database is running and there's a server listening at the port you specified, but it is of the wrong type.

Hard to say which of these is the case just going by the error message.

D. SM
  • 13,584
  • 3
  • 12
  • 21
  • I am not sure what I've changed, but now I don't get this error anymore. Instead I just get a timeout error. – Tsabary Apr 10 '20 at 07:32
  • If you already created a connection, Compass appears to show old (cached) data when it can't connect. If you hover over the right UI element it might tell you that it couldn't connect. – D. SM Apr 10 '20 at 07:35
  • I haven't made a local connection before. I don't see any cached data (I don't see any data at all). I have no problem connecting to Atlas though, which is weird, because it seems that this is what most people have problems with, but I had none. It's only connecting to my local DB that's causing me these issues. – Tsabary Apr 10 '20 at 07:39
  • 1
    Note also you can use URI to connect locally, e.g. mongodb://localhost and mongodb://localhost:27017/db . – D. SM Apr 10 '20 at 07:49
  • I'm not sure which is it, but I've resterted the server and used `mongodb://localhost:27017/db` to connect and it works now! Cheers – Tsabary Apr 10 '20 at 07:52
  • Compass doesn't require a replica set name. Also please post the version of Compass you are using when reporting problems. – Joe Drumgoole Apr 10 '20 at 23:16
0

I had the same problem working on a single machine for development as a replica set member(primary). I did this because I had to use @Transactional of spring-data-mongodb. What solved for me was logging to mongo shell and issuing: rs.initiate();

Aman
  • 1,627
  • 13
  • 19