"Chapter 4: Lab 2: Logic Operators" problem wording is confusing

At first, I thought it would mean something along these lines:

  $or: [ 
    {"founded_month":9, $or: [
      {"category_code": "web"}, {"category_code": "social"}

But was very surprised to see it’s two separate $or clauses after failing 3 times, because the wording implies only one global $or clause between founded year query and the month one.

1 Like

Hi @Vasya_Berdyaev,

Thanks for sharing your feedback. We will try to rephrase the problem statement to make it more clear.

~ Shubham

@Vasya_Berdyaev is right. I’m having the same problem and I came hare looking for a better phrasing for the problem

Its still the same… the language is too confusing …

I still would have got it wrong (because I messed up the syntax by not “pretty printing” my JSON), but I too was confused by the way the question was framed. Something like “How many companies were founded in either 2004 or October and also had category codes of either web or social?”

Hi @Phil_90571,

Welcome to the MongoDB Community Forum,

We apologize for the inconvenience caused to you.
We will surely consider your feedback and will try to rephrase the problem statement to make it more clear.

All the Best,

Any one who have better wordings with this? this is so confusing.

Thank you

Which part exactly is problematic? The year part, the month part or category codes? In this thread many reformulated the requirements in their own words. Was this helpful or more confusing?

The first step would be to determine what are the exact field names used in the collection. Then is there anything special about the data. There is for the month because it is a number, not a string, and the number represent the month number (1 being January) rather than the month index (which would be 0 for January is months are put in a array).

1 Like

May someone explain me why the result of the next two queries is different?
My query:

db.companies.count({$and:[{“category_code”:{$eq:“social”, $eq:“web”}},{$or:[{“founded_year”:2004},{“founded_month”:10}]}]})


Query from lesson:
db.companies.find({ “$and”: [
… { “$or”: [ { “founded_year”: 2004 },
… { “founded_month”: 10 } ] },
… { “$or”: [ { “category_code”: “web” },
… { “category_code”: “social” }]}]}).count()



{ category_code : { $eq : "social" , $eq : "web" } }

is equivalent to

{ "category_code" : { "$eq" : "web" } }
mongo shell> q = { category_code : { $eq : "social" , $eq : "web" } }
{ "category_code" : { "$eq" : "web" } }

The second $eq overrides the first one as with any other JSON document where keys are repeated.