Connect to the db from Compass

Can I try connecting to the cluster defined in “Chapter 1: Basic Aggregation - $match and $project - Lab - $match” from MongoDB Compass? I am able to connect from the shell but when I tried from Compass, it is connecting to a different cluster. I do not see the movies collections from Compass login. Can you please specify the connection details to connect from Compass.

Thank you.

@Balaji_V_80301

You can connect to the Atlas cluster using Compass, however the connection strings are somewhat different. As using Compass is not a major issue in the course and I don’t have the time currently to solve this for you, I’d suggest that you do some additional work and find out yourself how the two connection string (and the associated information required in Compass) could be done. Otherwise I’ll come back to this when I have more time. Good luck.

Thank you for the reply.

Sorry to have bothered you; when you get time, kindly send the options.

Meanwhile, I will keep trying and post it if I get through.

Best Regards,

Balaji.

@Balaji_V_80301

Sorry, I didn’t mean to be quite so terse. My reply was intended to explain why you might not get a very prompt response to this, as it takes time to translate the connection string as provided into Compass fields.

So let’s work this through. Here’s the connection string as provided:

“mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/aggregations?replicaSet=Cluster0-shard-0
–authenticationDatabase admin
–ssl
-u m121
-p aggregations
–norc

Now, first of all, notice that if you copy that string to your clipboard and open Compass, it will try to fill in what it can in the Connection dialog box. Basically, it will fill in the hostname field, the Port, and the Replica Set Name. So far, good.

Next notice that you are using authentication here, and that you are using the standard authentication mechanism (–ssl) with the username ‘m121’ and the password ‘aggregations’. So next fill those in. Everything else can be the default values.

This will get you to the cluster. Now notice that the connection string is augmented by the extension ‘/aggregations’. This tells you that the correct database to use is named ‘aggregations’; so finally you have to select that database manually from your list in Compass. And then you’re where you need to be.

It’s a LOT easier to do this from the shell IMHO. :wink:

3 Likes

Thank you. What I was missing was that last step - “so finally you have to select that database manually from your list in Compass”. Just missed to see the list of DBs (it is of course obvious). In the last course, the DB was the default one.
Thank you so much. I just feel more comfortable with GUI.

I’m encountering the red error message at the top of Compass:

“MongoDB not running on the provided host and port”

I do have success with Compass connecting to a Cluster of my own on Atlas that I worked with for M220 course, and other purposes.

But for this Aggregations M121 Cluster I consistently fail:

  • Tried Compass 1.18 Community (stable)
  • Tried Compass 1.18 (stable) (the “not Community” version)

SHELL
Just to note it: My shell connection (MongoDB shell version v3.6.6) of course is working fine for both:

M121 Aggregations Cluster: Yes

MongoDB server version: 3.6.13
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db
aggregations

My own Atlas Cluster (M220, other): Yes

MongoDB server version: 4.0.10
WARNING: shell and server versions do not match
MongoDB Enterprise ClusterWR03-shard-0:PRIMARY> db
test
MongoDB Enterprise ClusterWR03-shard-0:PRIMARY> show dbs
admin 0.000GB
cscie31 0.000GB
local 6.255GB
mean-udemy 0.000GB
mflix 0.133GB

COMPASS
But Compass only connects to one of them …
Below are the two Compass “Connection” forms I fill out - one works, the one for this M121 does not.
They both seem to me to be correct, and they seem to match the inputs I’ve seen in other M121 Forum Postings on this issue:



I wonder what I am missing ???
(It cannot have anything to do with that server version difference of 4.0.10 and 3.6.13 can it ???)

As to rationale for wanting to use Compass … (I like shell plenty) - I believe it will help see interim results, step by step, in building up the aggregation.

  • I am finding that can be a challenge at the shell, when a query might return to you, even for one document, to spill out an enormous array (e.g. air_routes Collection) with just far too many entries to scroll back to the top of the array in the shell, and see what is happening.
  • Compass shows you sample records in more manageable way (in my limited experience).

====================
COMPASS - WORKS:

Hostname: clusterwr03-shard-00-00-n783b.mongodb.net
Port: 27017
SRV Record: (off)
Authentication: Username / Password
Username: wr_mongodb_admin03
Password: ***********
Authentication Database: admin
Replica Set Name: ClusterWR03-shard-0
Read Preference: Primary
SSL: System CA / Atlas Deployment
SSH Tunnel: None
Favorite Name: MyClusterWR03FavoriteNameTag
CONNECT < click

SUCCESS
MongoDB 4.0.10 Enterprise

====================

COMPASS - DOES NOT WORK:

Hostname: cluster0-shard00-00-jxeqq.mongodb.net
Port: 27017
SRV Record: (off)
Authentication: Username / Password
Username: m121
Password: aggregations
Authentication Database: admin
Replica Set Name: Cluster0-shard-0
Read Preference: Primary
SSL: System CA / Atlas Deployment
SSH Tunnel: None
Favorite Name: MyM121FavoriteNameTag
CONNECT < click

Error seen: "MongoDB not running on the provided host and port"

Thanks for any comments etc.
William Reilly

1 Like

Hi @wreilly,

There is just one small typo in your hostname:

Hostname: cluster0-shard-00-00-jxeqq.mongodb.net

Please try again and let me know if it does not work. If it does not work, share the output when run the below command from the terminal:

  mongo "mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/test?replicaSet=Cluster0-shard-0" --ssl --authenticationDatabase admin --username m121 --password aggregations

Kanika

1 Like

Wow.

Thank you, Kanika. @Kanika
I now can get to the m121 aggregations Collection via Compass. :slight_smile:

Always helpful to have 2nd pair of eyes on something.

SHARD-00-00 (right) << Thank you
SHARD00-00 (wrong)

Also, in going through this, I’ve learned more about this “handshake / connection”. The mongo shell is bit more forgiving, and was actually able to recover from that partial typo(!) (details below), whereas Compass apparently less so.

(Also - fwiw - I don’t know how that missing ‘-’ hyphen occurred, as I expect I did copy & paste from the correctly formed URL on the MongoDB University course page:
https://university.mongodb.com/mercury/M121/2019_June/chapter/Chapter_0_Introduction_and_Aggregation_Concepts/lesson/59de3c10e433130e0a9628d2/lecture
mongo "mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017 … <<< Correct “shard-00-00”
)

MONGO SHELL

  • Even though I had the wrong URL, it still got there okay! (Surprising)

COMPASS

  • With that exact same wrong URL, simply failed immediately.

So, with having the experience of the (wrong) URL working on the shell, I never thought to scrutinize that URL, when pasting into Compass. (Sigh.)

SUMMARY

RECOVERY!:
Here is the essential log messaging during the connection handshaking, showing how it recovered:
############################################
connecting to: … shard00-00 <<<<< WRONG
Starting new replica set monitor for… shard00-00 <<<<< WRONG
Successfully connected to… shard-00-02
Successfully connected to… shard-00-01
changing hosts to … shard-00-00
from … shard-00-01
getaddrinfo(“cluster0-shard00-00-jxeqq.mongodb.net”) failed: nodename nor servname provided, or not known <<<<< WRONG
Successfully connected to cluster0-shard-00-00
############################################


DETAILS

############################################
SHARD-00-00 (right)
############################################
$ mongo “mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/aggregations?replicaSet=Cluster0-shard-0” --ssl --authenticationDatabase admin --username m121 --password aggregations

MongoDB server version: 3.6.13
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db
aggregations

############################################
SHARD00-00 (wrong)
############################################
$ mongo “mongodb://cluster0-shard00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/aggregations?replicaSet=Cluster0-shard-0” --ssl --authenticationDatabase admin --username m121 --password aggregations
MongoDB shell version v3.6.6
connecting to: mongodb://cluster0-shard00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/aggregations?replicaSet=Cluster0-shard-0
2019-06-27T13:02:32.129-0400 I NETWORK [thread1] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017
2019-06-27T13:02:32.255-0400 I NETWORK [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to cluster0-shard-00-02-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-02-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-06-27T13:02:32.257-0400 I NETWORK [thread1] Successfully connected to cluster0-shard-00-01-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-01-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-06-27T13:02:32.293-0400 I NETWORK [thread1] changing hosts to Cluster0-shard-0/cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017 from Cluster0-shard-0/cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017,cluster0-shard00-00-jxeqq.mongodb.net:27017
MongoDB server version: 3.6.13
2019-06-27T13:02:33.281-0400 I NETWORK [ReplicaSetMonitor-TaskExecutor-0] getaddrinfo(“cluster0-shard00-00-jxeqq.mongodb.net”) failed: nodename nor servname provided, or not known
MongoDB Enterprise Cluster0-shard-0:PRIMARY> 2019-06-27T13:02:34.723-0400 I NETWORK [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to cluster0-shard-00-00-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-00-jxeqq.mongodb.net:27017 with a 5 second timeout)

MongoDB Enterprise Cluster0-shard-0:PRIMARY> db
aggregations

As noted above, the essential logging messaging:
############################################
connecting to: … shard00-00
Starting new replica set monitor for… shard00-00
Successfully connected to… shard-00-02
Successfully connected to… shard-00-01
changing hosts to … shard-00-00
from … shard-00-01
getaddrinfo(“cluster0-shard00-00-jxeqq.mongodb.net”) failed: nodename nor servname provided, or not known
Successfully connected to cluster0-shard-00-00

1 Like

@wreilly

Note that your connection string for the shell is incorrect only in the first URL, the other two are just fine. The shell looks at all three, and then connected to the correct URL (the ones that worked). If you look at your messages when you logged onto the shell, you’ll see that you first connected to one of the servers (‘shard-00-02’ according to your report) and then found the other members of the replica set from their internal references. In Compass, the field only allows you to put in the first URL, which is incorrect, so Compass can’t find the replica set.

1 Like