Chapter 4 Lab 2: Logic Operators

Hello everyone! Im having trouble with this exercise. I can’t figure out what is wrong here.
The shell return the following error:
SyntaxError: missing ] after element list
But I cant find where is wrong.

This is my code:
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”} ] } ] } ] }).count()

Hi @Nicolas_Chinaglia, welcome to the community.

Well, you are on the right track, but just keep the following in mind:
The lab asks you to find the number of companies, which:

  • are either founded in the month of October OR in the year 2004
    AND
  • are having the category code as “social” OR “web”

I hope it helps. In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer.

3 Likes

It means you opening brackets [ do not match your closing brackets ].

3 Likes

My suggestion is to use some editor like notepad++ to split lines that form logical blocks then indent then and look at bracket matching (and commas between arguments).

Please also use code tags (the </> icon in editor) when you are posting code so it can be easily copied for us simple folks to understand code better and use it to troubleshoot :slight_smile: .

I also second @SourabhBagrecha tips…

4 Likes

Thanks for helping me! I had a better understanding of the problem and solved the lab. Thanks all!

2 Likes