Chapter 3 Logical Operators Quiz

While using Compass, I can search for the following: {watlev: {$eq: “always dry”}}, {depth: {$eq: “0”}}. The results come up as zero, which is fine. However, I’m having trouble figuring out the correct syntax when incorporating $or.

I believe this is what I should be using, but Compass will not accept it:
{$or [{watlev: {$eq: “always dry”}}, {depth: {$eq: “0”}}]}

Hi Ronald,

place a colon after the $or :wink:

The Docs gives you the correct Syntax:

{ $or: [ { <expression1> }, { <expression2> }, ... , { <expressionN> } ] }

And in your Screenshot there are missing curly braces at the beginning.

Your query should be:

{$or: [ {"watlev": {$eq: "always dry"}}, {"depth": {$eq: 0}} ] }

And pay Attention when you do copy&paste. The normal text written by you has not the right quotes. If you copy&paste my code there may be two newlines (/n) at the end.

Good Luck :four_leaf_clover:



{"$or": [{“depth”: 0}, {“watlev”: “always dry”}]} - its Returning 2331 documents
But {$or:[{‘watlev’:{$eq:‘always dry’}},{‘depth’:{$eq:‘0’}}]} - its returning 2329 What is the reason can some explain .

Hi @Priya_40322,

Please try running query again, I see similar results for both queries. You can view the following screenshots for both queries:

Please share the screenshots, if you see different count for both queries.


Hi @Priya_40322 that is because the data type for depth field. There are 99.9% string values and only 0.1% Int32 values. May be it’s just a display confusion in Compass.

In fact, most depth values are empty strings. It looks like mongodb is treating “” and 0 as “false”. It’s like Javascript. It could be intentional.

Hi @Stamatis_27661,

Mongo shell is a javascript interpreter but MongoDB Query Language (MQL) do not treat empty string ("") and 0 as false. Please refer the screenshot for further clarification.

We have three documents in a collection where the boy field contains three separate values true, false and 0. If we query for those documents where the boy field is false, it returns only one document and similarly for 0.

If you still have any doubt feel free to get back to us. Happy Learning :slight_smile:

Shubham Ranjan
Curriculum Support Engineer

Ok, good to know! I must get more info on the subject.