Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JNaeemGitonga/ba8a04e145cd13c559cb6d8c42c8c95e to your computer and use it in GitHub Desktop.
Save JNaeemGitonga/ba8a04e145cd13c559cb6d8c42c8c95e to your computer and use it in GitHub Desktop.
//MORNING ASSIGNMENTS
1. db.restaurants.find()
2. db.restaurants.find().sort({name: 1}).limit(10)
3. var documentId = ObjectId('5934b07a13358bfc0a5434b4'); db.restaurants.findOne({_id: documentId});
4. db.restaurants.find({borough: "Queens"}).pretty()
5. db.restaurants.count()
6. db.restaurants.find({"address.zipcode": "11206"}).pretty()
7. db.restaurants.remove({_id: ObjectId("593578055412460076a9a12c")})
8. db.restaurants.update( { _id: ObjectId("593578055412460076a9a12d") }, { $set:{ name: "Bizz Bar Bang" } } )
9. db.restaurants.update( { "address.zipcode" : "10035"}, { $set:{ "address.zipcode": "10036" } }, { multi: true } )
//AFTERNOON ASSIGNMENTS
db.restaurants.find(
{
cuisine: {$ne: "Not Listed/Not Applicable"},
borough: {$ne: "Missing"},
grades: { $exists:true, $ne: "Not Yet Graded", $elemMatch:{score:{$ne:-1}} }
}).pretty()
How many were filtered out?: (I know y'all wanted that) 808 (can you feel that B-A-S-S bass)
List of unique cuisines that match our criteria:
db.restaurants.distinct(
"cuisine",
{
cuisine: {$ne: "Not Listed/Not Applicable"},
borough: {$ne: "Missing"},
grades: { $exists:true, $ne: "Not Yet Graded", $elemMatch:{score:{$ne:-1}} }
}
)
First five restaurants with the lowest positive score in one of their gradings:
db.restaurants.find(
{
cuisine: {$ne: "Not Listed/Not Applicable"},
borough: {$ne: "Missing"},
grades: { $exists:true, $ne: "Not Yet Graded", $elemMatch:{score:{$gt:-1}} }
}).sort({'grades.score': -1}).limit(5).pretty()
the restaurants which have only been graded A
db.restaurants.find(
{
cuisine: {$ne: "Not Listed/Not Applicable"},
borough: {$ne: "Missing"},
grades: { $exists:true, $ne: "Not Yet Graded", $elemMatch:{grade: "A"} }
}).pretty()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment