https://cloud.mongodb.com/v2/5c45e4dfc56c98b1ecc199dc#clusters
1) Create your Atlas Sandbox cluster:
https://cloud.mongodb.com/links/registerForAtlas
2) connect:
click on "connect to cluster"
click on "connect to the mongo shell"
copy the connection string: (for example)
mongo "mongodb+srv://cluster0xxxxx" --username m001-student
password: m001-mongodb-basics
show dbs #show databases
use video #select database called video
db #show current database
show collections
#insert many
db.movieDetails.insertMany([{"title":"saw","year":2018,"actors":"pepito"},{"title":"saw2", "year":2019, "actors":"pepito"}])
#How many documents in video.movieDetails match the filter {genres: "Comedy"}?
db.movieDetails.find({"genres":"Comedy"})
db.movieDetails.count({"genres":"Comedy"}) #749
#Examples using other filters
db.movieDetails.count({"awards.wins":2,"awards.nominations":2})
db.movieDetails.find({"awards.wins":2,"awards.nominations":2}).count()
#12
db.movieDetails.find({"writers":["Ethan Coen", "Joel Coen"]}).pretty()
#Logic operators
$and
Syntax: { $and: [ { <expression1> }, { <expression2> } , ... , { <expressionN> } ] }
#Comparison query operators (https://docs.mongodb.com/manual/reference/operator/query-comparison/)
conditions: $ne (not equal) , $exists , $eq , $gt, $gte , $in (matches any of the values) $nin (matches none of the values)
#How many documents have the poster section set to null? Ignore any documents that do not contain the rating key.
db.movieDetails.find({$and: [{poster: null}, {rating: {$exists: true}}]}).count()
#answer:0
db.movieDetails.find({$and: [{poster: null}, {director: {$exists: true}}]}).count()
1252
db.movieDetails.find( { "director": { $ne: "Joel Coen" } }).count()
db.movieDetails.find({actors: {$in: ["Jack Nicholson", "John Huston"]}}).count()
db.movieDetails.find({actors: {$nin: ["Jack Nicholson", "John Huston"]},year:{$gt:2000}}).count()
db.movieDetails.find({"year":{$gte:2018}})
#db.collection.update(query, update, options)
#Update operators
#https://docs.mongodb.com/manual/reference/operator/update/
$inc (increments), $set (replaces), $min (updates the field if the specified value is less than the existing field value.)
db.movieDetails.update({'title':'saw2'},{$set:{'title':'saw_2'}})
db.collection.deleteMany()
db.movieDetails.deleteMany({"title": "saw_2"})