Chapter 4 Lab 2 Logic Operators

Hi,

I have a question regarding why we need an explicit “$and” statement here:
db.companies.find({"$and":[{"$or":[{“founded_year”:2004},{“founded_month”:10}]},{"$or":[{“category_code”:“social”},{“category_code”:“web”}]}]}).count()

as compared to an implicit “$and” statement like this:
db.companies.find({"$or":[{“founded_year”:2004},{“founded_month”:10}], “$or”:[{“category_code”:“social”},{“category_code”:“web”}]}).count()

The implicit “$and” method does not give the right answer but I am not too sure why.

Thank you!

2 Likes

Welcome to the community @Zephaniah!

According to the documentation, implicit $and is not supported when using multiple $or operators.

Maybe someone will shed some light on the internals here.

Thanks,
Mahi

2 Likes

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