Problem in chapter 3

I’ve got to chapter 3 and now I cannot proceed with the tests required. I always get a “Syntax Error near unexpected token” when I try to do my exercises in the IDE. It starts with getting a random document from the collection. I tried to use

db.zips.findOne({"city","ALPINE"}); , 
db.sample_training.zips.findOne({"city","ALPINE"}); , 
db.zips.find({"city","ALPINE"}); , 
db.sample_training.zips.find({"city","ALPINE"}); 
db.zips.find({city,"ALPINE"}); , 
db.sample_training.zips.find({city,"ALPINE"});  

and the same with findOne. I have no clue what is wrong or how to proceed with this query. Please help me.

Hi @Armando_Halpern,

Welcome to the MongoDB University forums :sparkles:

You need to replace , with the colon : in the MongoDB query command after “city”.

Attaching the screenshot for your reference:

We suggest you visit our MongoDB Docs Page to learn more about MongoDB find() method.

Thanks,
Kushagra

I did that but keep getting syntax errors: “syntax error near unexpected token”

Connect to your db and then run the query.It will work

Sorry, but I want to run the query within the course material. Is there any way to do it?

Hi @Armando_Halpern,

You need to first connect the IDE to your MongoDB cloud database using the srv connection string and then run the query in order to get the result.

mongosh 'mongodb+srv://sandbox.xxxx.mongodb.net/myFirstDatabase" --username m001-student'

You can find your srv connection string on the MongoDB Atlas Cloud webpage.

References:

I hope it helps!

Thanks,
Kushagra

Have you created your Sandbox cluster and loaded the sample data?
If yes you will get your connect string from Atlas account
Paste that connect string in your IDE

mongosh “your connect string”

In the string that you sent, do I replace the xxxx by something else?

On my Atlas, I have:
CLUSTER TIER
M0 Sandbox (General)

Hi @Armando_Halpern,

Please go through the given below documentation to find the srv connection string from your MongoDB Atlas cluster.

Thanks,
Kushagra

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