Skip to content

Instantly share code, notes, and snippets.

@DaniiNyan
Last active July 21, 2022 02:59
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save DaniiNyan/39758d25881cce4aa2c264a84884eaca to your computer and use it in GitHub Desktop.
Save DaniiNyan/39758d25881cce4aa2c264a84884eaca to your computer and use it in GitHub Desktop.
  • How many zips in the sample_training.zips dataset are neither over-populated nor under-populated? In this case, we consider population of more than 1,000,000 to be over- populated and less than 5,000 to be under-populated.
db.zips.find({
              $nor: [
                { pop: { $gt": 1000000 } },
                { pop: { $lt: 5000 } }
              ]
            }).count()
  • How many companies in the sample_training.companies dataset were either founded in 2004, or in the month of October and either have the social category_code or web category_code?
db.companies.find({
    $and: [
        {
            $or: [{founded_year: 2004}, {founded_month: 10}]
        },
        {
            $or: [{category_code: "web"}, {category_code: "social"}]
        }
    ]
}).count()
  • How many companies in the sample_training.companies collection have the same permalink as their twitter_username?
db.companies.find({ 
    $expr:  { $eq: ["$permalink", "$twitter_username"] }
}).count()
  • What is the name of the listing in the sample_airbnb.listingsAndReviews dataset that accommodates more than 6 people and has exactly 50 reviews?
?
@iamramann
Copy link

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

@jomas94
Copy link

jomas94 commented Apr 30, 2021

db.listingsAndReviews.find({ "reviews": { "$size":50 },
"accommodates": { "$gt":6 }})

@georgesfarah
Copy link

db.listingsAndReviews.find({
    "property_type": "House",
    "amenities": {
        "$all": ["Changing table"]
    }
}).count()
db.listingsAndReviews.find({
    "$and": [{
        "property_type": "House"
    }, {
        "amenities": {
            "$all": ["Changing table"]
        }
    }]
}).count()

@Forz70043
Copy link

Forz70043 commented Jun 11, 2021

Hi everyone!
I have a question about chapter 4 lecture 6 lab. 2: "How many inspections from the sample_training.inspections collection were conducted in the city of NEW YORK?"
My query: db.inspections.find({"address.city":"New York"}).count()
Result: 5

But it's not correct... Can anyone explain to me why ?

SOLVED: it's "NEW YORK"

@georgesfarah
Copy link

Hi everyone!
I have a question about chapter 4 lecture 6 lab. 2: "How many inspections from the sample_training.inspections collection were conducted in the city of NEW YORK?"
My query: db.inspections.find({"address.city":"New York"}).count()
Result: 5

But it's not correct... Can anyone explain to me why ?

SOLVED: it's "NEW YORK"

I think you should write:
db.inspections.find({"address.city":"NEW YORK"}).count()

@sammiearchie77
Copy link

haha thanks for the help

@surajkadam23
Copy link

How many companies in the sample_training.companies collection have the same permalink as their twitter_username?
db.companies.find({
$expr: { $eq: ["$permalink", "$twitter_username"] }
}).count()
after using this query it show the result 0

When i enter the same query in Atlas collections filter :
{"$expr":{"$eq":["$permalink","$twitter_username"]}}
It shows many results.
can someone help me with this issue

@suedeapple
Copy link

suedeapple commented Jul 25, 2021

$expr:

"$expr":

@Hrsikesa108
Copy link

we can check what collections we have by giving show dbs, after selecting any one database, how to navigate back to parent databases ?

@elpapx
Copy link

elpapx commented Nov 20, 2021

In the first exercise, it's "$gt" : 5000, and "$lt": 100000

@ProfessorDobby
Copy link

we can check what collections we have by giving show dbs, after selecting any one database, how to navigate back to parent databases ?

use database_name

@rishikey
Copy link

In the first exercise, it's "$gt" : 5000, and "$lt": 100000

i guess it should be $gte and $lte

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment