Chapter 4: Lab 2 Logic Operators

Problem:

To complete this exercise connect to your Atlas cluster using the in-browser IDE space at the end of this chapter.

How many companies in the sample_training.companies dataset were

either founded in 2004

  • [and] either have the social category_code [or] web category_code,

[or] were founded in the month of October

  • [and] also either have the social category_code [or] web category_code?

Copy/paste the exact numeric value (without double quotes) of the result that you get into the response field.

My Question
I am not able to find out why the below query gives me the wrong result. And also the below query runs in Atlas but throws a syntax error if I run it in the MongoDB shell with the db.companies.find()

  {"$or":[   {"$and": [ {“founded_year”:2004},{"$or":[ {"category_code":"web"},{"category_code":"social"}] }]} ,{"$and": [{"founded_month":10},{"$or":[ {"category_code":"web"},{"category_code":"social"}] }]}]}

Thanks

Hi @madhu_prasath, welcome to the community :wave:

Your query looks good to me, can you please post a screenshot of the same?

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

Hi Sourabh,

Firstly a huge thanks for the prompt response!

Kindly find the screenshot of mongoshell.

Error_mongoDB

Thanks,
Madhu

Hi @madhu_prasath, thanks for the screenshot.
Seems like you have a typo in your query(backticks instead of double quotes).
Try the following:

{"$or":[   {"$and": [ {"founded_year":2004},{"$or":[ {"category_code":"web"},{"category_code":"social"}] }]} ,{"$and": [{"founded_month":10},{"$or":[ {"category_code":"web"},{"category_code":"social"}] }]}]}

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

1 Like

Thanks again Sourabh !