Chapter 4 Expressive query operator: localhost result always 0


I’m trying to work mainly from my terminal. My issue is when I query from the local terminal on my Mac M1 machine, the result is always 0.
I check the query just in case in Atlas it works. (see screenshot)

but when I use the same query in the terminal it shows 0. (see screenshot from my terminal)

What might be the problem ?

Thanks in advance,

Even a simple operation is not giving a result

I wonder if it is due to some connection problems:

Please help since I cant see results when I try to pass quizzez.

Did you switch to the correct DB?
In your connect string you are connecting to sandbox
show the output of
show collections

Hi @Rashad_Bayram,

Welcome to the MongoDB Community Forum :sparkles:

As @Ramachandra_Tummala mentioned it is happening because you are not switched to the correct database within your MongoDB Cloud cluster.

Kindly use the use <database_name> to switch to the db, then fire the query command to get the correct output. Also, use the show collection command to view all the collection names within the database and make sure that the collection name is there for which you are querying.!!

Please let us know if you have any additional questions or doubts.!!
Happy Learning :slight_smile:

Kind Regards,

Thanks for your feedback. Maybe it’s silly but to confirm. I need to connect to the primary database which is shown on this screenshot, correct?

Yes @Rashad_Bayram, moreover it would be done automatically if you are using your normal srv connection string.


Any reference to source how to connect via “normal srv connection string”?

Thanks in advance,

Hi @Rashad_Bayram,

Open your Atlas Cloud Cluster
Hit Connect → I have the mongo shell installed → Copy the srv string.


Hi @Kushagra_Kesav ,
I tried to connect to the Primary and secondary DB shown below.
Screen Shot 2021-07-19 at 5.00.26 PM

When I query data it still shows 0.

This is the terminal screenshot:

As you can see I connected via primary DB.

I used srv connection you referred to. No success.

Please help. i might still be doing something wrong I guess.
Thanks in advance,

Your connection string is not ok
Whatever you put after / is treated as dbname
You can verify yourselves with command db.It will show you sandbox-shard-00-02
Since this db is empty it will not give any rows
You have to switch to the correct db after you connected to the mongodb with
use db command

Try this
mongo mongodb+srv:// --username m001-student --password m001
It is not mandatory to give the dbname in the connect string
By default it will put you in test(dummy) DB

Also your query is not correct
When you are connected to a db by use db there is no need to specify the db_name in your find query
Just run

Your attempt to connect to primary is also not correct.When you use SRV no need to specify primary as Kushagra_Kesav mentioned

You will get the correct string from connect from your Atlas


@Ramachandra_Tummala I appreciate your feedbakc. Let me try.

1 Like

@Ramachandra_Tummala it worked. I can’t thank you enough.


Hey @Rashad_Bayram,

We are glad that you were able to resolve your issue. :clap:
Thank you @Ramachandra_Tummala for your super-useful response to Rashad.!!

Happy Learning :slightly_smiling_face:

Kind Regards,

1 Like

Thank you @Kushagra_Kesav too. So far I’m really enjoying my experience here because of such nice supportive people around. :slight_smile:


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.