M001 - CH4 - Lab 1: Array Operators

What is the name of the listing in the sample_airbnb.listingsAndReviews dataset that accommodates more than 6 people and has exactly 50 reviews?

  • exactly 50 reviews? - don’t exist:
    Here are some examples of the queries I have used as proof:

{ “$expr”: {"$eq":[ “$review_scores.review_scores_value”, 2]}} —> returns 16
{ “$expr”: {"$eq":[ “$review_scores.review_scores_value”, 5]}} —> returns 3
{ “$expr”: {"$eq":[ “$review_scores.review_scores_value”, 50]}} —> returns 0

I might be wrong, but I might have found a typo in the Lab 1: Array Operators - requirements.

There is no typo. You are querying the wrong field. This chapter is about array. There is an array named reviews in documents of this collection.

1 Like

Hi there,

I’am also doing this lab and I just wanted to discuss a little bit about the logic of what I wrote :

db.listingsAndReviews.find({$and:[{"accommodates":6},{reviews:{"$size":50}}]}).count()

So , if we translate this command we would get something like :

Return within the collection listingsAndReviews , the number of documents that accomodates 6 people and have 50 reviews. 

Right ?

I don’t see any need in this case to use the $expr operator in this exercise , or am I wrong ?

That’s sound right.

Did you tried it? Did you get the correct count for the lab? If both are yes then you are definitively not wrong.

However, even $and is redundant, as there is am implicit AND in simple query like that. So you could replace

{$and:[{"accommodates":6},{reviews:{"$size":50}}]}

with

{"accommodates":6, "reviews":{"$size":50}}

and get the same result.

1 Like

the result is there, but what I would have expected would have been a query to fetch the value of the “name” field from the DB entry without looking to read in Atlas (“because it’s easier”)

since I am new to this, I do not know how to do that