Skip to content

Instantly share code, notes, and snippets.

@DaniiNyan
Last active July 21, 2022 02:59
Show Gist options
  • 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?
?
@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