Chap4, Lesson2, Lab2: Help

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?

This my solution that I think it’s right:

  db.companies.find({"$or":

	[ 
		{"$and":
			[
			  {founded_year: 2004},
			  {"$or":
				 [
				  {category_code:{"$eq":"web"}},
				  {category_code:{"$eq":"social"}}
				 ]
			  }
			]
		 },
	
	 	{"$and":
			[
			  {founded_month: "October"},
			  {"$or":
				 [
				  {category_code:{"$eq":"web"}},
				  {category_code:{"$eq":"social"}}
				 ]
			  }
			]
		}
       ]
		}).count()

the result: 81

But it seems not be correct when I submit

I need your help

Hi @Franck_Tchamo , welcome to the community.

Well, you are on the right track, but the following description will make the problem even simpler to understand:

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.

2 Likes

I had forgotten something in my query:
"October" should be replaced by 10

and by using logical mathematics What you said It’s true:
My query is too long but It gives the result…

Thank you a lot

1 Like