Logical Operators - Quiz Answer doesn't match

Q.Connect to our class Atlas cluster from the mongo shell or Compass and view the ships.shipwrecks collection. In this collection, watlev describes the water level at the shipwreck site and depth describes how far below sea level the ship rests. How many documents in the ships.shipwrecks collection match either of the following criteria: watlev equal to “always dry” or depth equal to 0.

When I Run this query — {$or: [{depth: 0}, {watlev: “always dry”}]}

  • i get 2329 records.

But options given show 2331 as correct answer. May be data is updated by someone?

Regards,
Kishore

I got 2331 records only when using your query when I ran in our Atlas cluster i.e .cluster0-shard-00-00-jxeqq.mongodb.net. Please share the screenshot.

Kanika

HI,
Today I’m getting 2331 records. Yesterday it was 2329, don’t know the reason why was that.
Thanks .
Regards,
Kishore

1 Like

Got the difference.

When you used:

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

You get 2329 results as you have surrounded 0 with quotes.

When you remove quotes around 0 ,

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

You will get 2331 results.

You can see those 2 records like this:

You will get 0 records if you use string ‘0’.

Kanika

1 Like

See my screenshot, it’s looks not correct.

@Tim,

What Kanika noticed is that, in your screen shot, your filter is assigning the string “0” to depth field. The filter {$or: [{depth: ‘0’}, {watlev: “always dry”}]} will return 2329 documents.

So, the number 0 should be assigned to the depth field in your filter. The filter {$or: [{depth: 0}, {watlev: “always dry”}]} will return 2331 documents.

2 Likes

Hi Everyone, i had this some problem

{$or: [{depth:0}, {watlev:“always dry”}]} - 2331 records
{$or: [{depth:0}, {watlev:“awalys dry”}]} - 2 records