I am trying to understand how to write a query for this lab

Problem:

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

Copy/Paste the value of the “name” field into the response field without quotation marks.

My Input : db.listingsAndReviews.find( {{“accommodates” : ["$gt": 6]}, {"$number_of_reviews" : ["$eq" : 50]}}).count()

Hello,

First, your logic is correct. But the syntax for most of MQL operators is:

  • a:{$gt:"b"}. In general key:{ $operator:"value" }.

As a suggestion, practice this a bit this, till it sticks to your mind, just by looking at the manual’s examples.

  • The field "$number_of_reviews" I don’t think it exists, but number_of_reviews or something similar.

  • Remember that $eq is not necessary: mongo adds it for us. Then, a:"b" is same as a:{$eq:b}

My logic is working when i am running in pieces.

MongoDB Enterprise atlas-nzw8k3-shard-0:PRIMARY> db.listingsAndReviews.find( {“accommodates” : {"$gt": 6}}, {“number_of_reviews” : 50} , {“name” : “$all”} ).pretty()

{ “_id” : “10006546”, “number_of_reviews” : 51 }
{ “_id” : “10051164”, “number_of_reviews” : 1 }
{ “_id” : “10166883”, “number_of_reviews” : 22 }
{ “_id” : “10317142”, “number_of_reviews” : 32 }
{ “_id” : “1036027”, “number_of_reviews” : 71 }
{ “_id” : “10423504”, “number_of_reviews” : 139 }
{ “_id” : “10449328”, “number_of_reviews” : 0 }
{ “_id” : “10486984”, “number_of_reviews” : 77 }
{ “_id” : “10548991”, “number_of_reviews” : 45 }
{ “_id” : “10581101”, “number_of_reviews” : 77 }
{ “_id” : “1066648”, “number_of_reviews” : 0 }
{ “_id” : “10671783”, “number_of_reviews” : 0 }
{ “_id” : “10857454”, “number_of_reviews” : 89 }
{ “_id” : “1090153”, “number_of_reviews” : 3 }
{ “_id” : “10932304”, “number_of_reviews” : 44 }
{ “_id” : “1095174”, “number_of_reviews” : 119 }
{ “_id” : “1104768”, “number_of_reviews” : 103 }
{ “_id” : “1112838”, “number_of_reviews” : 129 }
{ “_id” : “11223389”, “number_of_reviews” : 112 }
{ “_id” : “11413023”, “number_of_reviews” : 229 }

By running below command i am getting “errmsg” : “Unsupported projection option: number_of_reviews: { $size: 50.0 }”

db.listingsAndReviews.find( {“accommodates” : {"$gt": 6}}, {“number_of_reviews” :{"$size": 50}} , {“name” : “$all”} ).pretty()

As per the question i have to find out the “name” and which meets two conditions (more than 6 and exactly 50).

Am i missing any bracket?

There are extra brackets. The syntax is:

db.listingsAndReviews.find({queries}, {projection..}, {options..})

MongoDB interprets the command as I described above, and thinks you are projecting, but the projection number_of_reviews: { $size: 50.0 } can’t be parsed, and it errors out.

Then

db.listingsAndReviews.find( {“accommodates” : {"$gt": 6}, “number_of_reviews” :{"$size": 50} , “name” : “$all”} ).pretty()

Edit: Yet, this will work but name:"$all" is probably not what you look for. Take a look at the docs for $all.