Skip to content

Instantly share code, notes, and snippets.

@afonsoaugusto
Last active June 4, 2018 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afonsoaugusto/50b1d0cc188e3ddb8dd6aecf503f948a to your computer and use it in GitHub Desktop.
Save afonsoaugusto/50b1d0cc188e3ddb8dd6aecf503f948a to your computer and use it in GitHub Desktop.
wget https://s3.amazonaws.com/edu-downloads.10gen.com/M001_2018_May/static/handouts/m001_comparisonOperators.js
wget https://s3.amazonaws.com/edu-downloads.10gen.com/M001_2018_May/static/handouts/m001_element_operators.js
wget https://s3.amazonaws.com/edu-downloads.10gen.com/M001_2018_May/static/handouts/m001_logical_operators.js
wget https://s3.amazonaws.com/edu-downloads.10gen.com/M001_2018_May/static/handouts/m001_all_operator.js
wget https://s3.amazonaws.com/edu-downloads.10gen.com/M001_2018_May/static/handouts/m001_size_operator.js
wget https://s3.amazonaws.com/edu-downloads.10gen.com/M001_2018_May/static/handouts/m001_elemMatch_operator.js
wget https://s3.amazonaws.com/edu-downloads.10gen.com/M001_2018_May/static/handouts/m001_regex_operator.js
mongo "mongodb+srv://sandbox-felrd.mongodb.net/test" --username m001-student
pwd: m001-mongodb-basics
Quiz:
db.movieDetails.find({writers: {$in: ["Ethan Coen" , "Joel Coen"]}}, {_id: 0, title: 1, rated: 1}).count()
3
{atmosphericPressureChange : {$exists:false }}
40668
{$or :[{watlev: 'always dry'},{depth:0}]}
2331
{sections: {$all: [ "AG1", "MD1", "OA1" ]}}
10200
{sections: {$size: 2}}
2656
{results: {$elemMatch: {product: "abc", score: 7}}}
124
mongo "mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/test?replicaSet=Cluster0-shard-0" --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics
/*Connect to our class Atlas cluster from Compass and view the citybike.trips collection.
Use the schema view and any filters you feel are necessary to determine the range of values for the usertype field.
Which of the following are values found in this collection for the field usertype?
*/
db.trips.aggregate([
{"$group" : {_id:"$usertype", count:{$sum:1}}}
])
/* 1 */
{
"_id" : "Subscriber",
"count" : 1842667.0
}
/* 2 */
{
"_id" : "Customer",
"count" : 147606.0
}
/*
Connect to our class Atlas cluster from Compass and view the 100YWeatherSmall.data collection.
Using the Schema view, explore the wind field. The wind field has the value type of document.
Which of the following best describes the schema of this embedded document?
*/
# Three fields -- two with the value type "document", one with the value type "string"
/*
Connect to the M001 class Atlas cluster from Compass and view the 100YWeatherSmall.data collection.
What is the value type of the "wind.speed.rate" field?
*/
#Double
/*
How many documents in the citibike.trips collection have the key tripduration set to null?
Ignore any documents that do not contain the tripduration key.
*/
db.trips.find({"tripduration" : {$exists:true} , "tripduration" :null }).count()
3
/*
Using the video.movieDetails collection, which of the queries below would produce output documents that resemble the
following. Check all that apply.
{ "title" : "P.S. I Love You" }
{ "title" : "Love Actually" }
{ "title" : "Shakespeare in Love" }
NOTE: We are not asking you to consider specifically which documents would be output from the queries below,
but rather what fields the output documents would contain.
*/
db.movieDetails.find({}, {title: 1, _id: 0})
db.movieDetails.find({year: 1964}, {title: 1, _id: 0})
/*
Please connect to the M001 class Atlas cluster from the mongo shell or Compass and view the video.movies collection.
How many movies match the following criteria?
The cast includes either of the following actors: "Jack Nicholson", "John Huston".
The viewerRating is greater than 7.
The mpaaRating is "R".
*/
db.movies.find({
cast: {$in: [ 'Jack Nicholson', 'John Huston']},
viewerRating: {$gt: 7},
mpaaRating: 'R'
}).count()
8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment