Can't connect to lab database via shell

Not sure how to describe these windows, so I’ll use window1 for the Terminal window where I’d normally start Mongo by typing “mongod”, and window2 to describe the Terminal window where I start the shell by typing “mongo”.
When I paste the command from Lesson 2.3, part 1 into window1, my installation appears to connect to the database. However, when I enter “show collections” in window1, nothing happens:
window1
Switching over to window2 and entering the same command gives the same result (namely, nothing):
window2
What am I missing here?

In the top window you are connected to the shared cluster. There is no collection probably because the default database has none. You may use show dbs to show the list of databases and then use DatabaseName to select the database specified in the course.

In the second window you are connected to a local instance.

To add…

Window 1

image

  1. The “mongodb+srv…” connection string you used with mongo connects you to a database service hosted in the Cloud and auto-managed by MongoDB hence the reason why you never needed to run mongod. This service is called MongoDB Atlas.
  2. The /test part in the connection string connects to the test database on initial login. You can change it to whatever db you’d like to be connected to at first login.
  3. The test database is the default database if you don’t specify a db. This db is typically empty until you create a collection.
  4. Whilst connected, @steevej-1495 mentioned that you can switch to another db by executing:
    use database_name

Window 2

image

  1. Running mongod without additional arguments will create a local server instance that will run on your local machine implicitly using the following default options:

    • Host: localhost or 127.0.0.1
    • Port: 27017
    • DB Path: /data/db

    If you look at the fourth line, you’ll see that you’re connected to 127.0.0.1 at port 27017

  2. Running mongo without additional arguments will connect to an instance running on your local machine using the default host and port mentioned above, however, because you didn’t specify a db, it will connect to the test db.

PS: In your first sentence, you’ve got the windows mixed up.

1 Like

Actually, I don’t think I had the windows mixed up; they were labeled exactly as I intended. However, based on careful reading of your post, it seems I entered the connection string into what I referred to as window1 (where I would normally type “mongod”), instead of into window2 (where I would start the mongo shell). Quitting Terminal and pasting the connection string into a new Terminal window did the trick.

Thanks!