This was given at an Azure meetup in 2018. It demonstrates the basics of MongoDB, running MongoDB Atlas on Microsoft Azure, and connecting to MongoDB Stitch.
Full deck at http://l.gsky.us/#!mdbmsft2018
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Microsoft cloud workshop - automated cloud service for MongoDB on Microsoft Azure
1. MONGODB ATLAS & MICROSOFTMONGODB ATLAS & MICROSOFT
AZUREAZURE
HANDS-ON EXERCISESHANDS-ON EXERCISES
Solutions Architect @ MongoDB |
Deck & Content |
Registration Link |
chris.grabosky@mongodb.com
l.gsky.us/#!mdbms 2018
l.gsky.us/#!mdbms 2018reg
Click Here For Printable Version
Speaker notes
On demand lab - Automated cloud service for MongoDB on Microsoft Azure - 14/11/2018 New York is currently scheduled
and ready for use on Wednesday, November 14, 2018.
The lab activation details are as follows:
Sign-Up Link (For All): http://bit.ly/2RBaRj6
Support Link (For Instructors / Proctors): http://bit.ly/mcw-support
It is recommended that you share the sign-up link with participants only during the specified lab time 09:00 AM (UTC-
05:00) Eastern Time (US & Canada) on Wednesday, November 14, 2018.
This information is shared with:
Chris Grabosky
Eugene Kang
Valmik Mehta
Mohan Das
Please share this information with other instructors / proctors, who were not tagged with this lab request.
4. AT THE END OF THISAT THE END OF THIS EXERCISE 1EXERCISE 1
YOU SHOULD BE ABLE TO...YOU SHOULD BE ABLE TO...
Deploy a MongoDB Atlas Cluster (free-tier M0 or paid
M10+)
Understand basics of creating users and controls in
MongoDB Atlas
Know the difference between Atlas users and MongoDB
Users
8. AT THE END OF THISAT THE END OF THIS EXERCISE 2EXERCISE 2
YOU SHOULD BE ABLE TO...YOU SHOULD BE ABLE TO...
Launch Compass (tool to explore, visualize, optomize,
and modify MongoDB data) and connect to that cluster
Use Compass to create a database, create a collection,
and import a data set into that collection
Use Compass to create, read, update, and delete
(CRUD) documents in a collection
13. CONNECTION STRINGSCONNECTION STRINGS
IF YOUR CLUSTER WORKS, USE IT, BUT...IF YOUR CLUSTER WORKS, USE IT, BUT...
Key Value
Server mdbazuretraining-v9iwf.azure.mongodb.net
SRV Record Yes on Switch
Authentication Username/Password
Username azureacct
Password azurepasswd
Auth DB admin
21. M001 CM001 CRRUD: FIND ME MOVIES...UD: FIND ME MOVIES...
Question Answer
From 1987
"Comedy" as one of their genres
"Comedy" as only genre
"Comedy" or "Drama"
"Comedy" and "Drama
IMDB Rating > 8.0 and PG Rating
Whole title of "Dr. Strangelove"
22. M001 CM001 CRRUD: FIND ME MOVIES...UD: FIND ME MOVIES...
Question Answer
From 1987
"Comedy" as one of their genres
"Comedy" as only genre
"Comedy" or "Drama"
"Comedy" and "Drama
IMDB Rating > 8.0 and PG Rating
Whole title of "Dr. Strangelove"
{year:1987}
23. M001 CM001 CRRUD: FIND ME MOVIES...UD: FIND ME MOVIES...
Question Answer
From 1987
"Comedy" as one of their genres
"Comedy" as only genre
"Comedy" or "Drama"
"Comedy" and "Drama
IMDB Rating > 8.0 and PG Rating
Whole title of "Dr. Strangelove"
{year:1987}
{genre:"Comedy"}
24. M001 CM001 CRRUD: FIND ME MOVIES...UD: FIND ME MOVIES...
Question Answer
From 1987
"Comedy" as one of their genres
"Comedy" as only genre
"Comedy" or "Drama"
"Comedy" and "Drama
IMDB Rating > 8.0 and PG Rating
Whole title of "Dr. Strangelove"
{year:1987}
{genre:"Comedy"}
{genres:["Comedy"]}
25. M001 CM001 CRRUD: FIND ME MOVIES...UD: FIND ME MOVIES...
Question Answer
From 1987
"Comedy" as one of their genres
"Comedy" as only genre
"Comedy" or "Drama"
"Comedy" and "Drama
IMDB Rating > 8.0 and PG Rating
Whole title of "Dr. Strangelove"
{year:1987}
{genre:"Comedy"}
{genres:["Comedy"]}
{genres:{$in:["Comedy", "Drama"]}}
26. M001 CM001 CRRUD: FIND ME MOVIES...UD: FIND ME MOVIES...
Question Answer
From 1987
"Comedy" as one of their genres
"Comedy" as only genre
"Comedy" or "Drama"
"Comedy" and "Drama
IMDB Rating > 8.0 and PG Rating
Whole title of "Dr. Strangelove"
{year:1987}
{genre:"Comedy"}
{genres:["Comedy"]}
{genres:{$in:["Comedy", "Drama"]}}
{ genres: { $all: ["Comedy", "Drama"] } }
27. M001 CM001 CRRUD: FIND ME MOVIES...UD: FIND ME MOVIES...
Question Answer
From 1987
"Comedy" as one of their genres
"Comedy" as only genre
"Comedy" or "Drama"
"Comedy" and "Drama
IMDB Rating > 8.0 and PG Rating
Whole title of "Dr. Strangelove"
{year:1987}
{genre:"Comedy"}
{genres:["Comedy"]}
{genres:{$in:["Comedy", "Drama"]}}
{ genres: { $all: ["Comedy", "Drama"] } }
{"imdb.rating" : {$gt: 8.0}, rated:"PG"}
28. M001 CM001 CRRUD: FIND ME MOVIES...UD: FIND ME MOVIES...
Question Answer
From 1987
"Comedy" as one of their genres
"Comedy" as only genre
"Comedy" or "Drama"
"Comedy" and "Drama
IMDB Rating > 8.0 and PG Rating
Whole title of "Dr. Strangelove"
{year:1987}
{genre:"Comedy"}
{genres:["Comedy"]}
{genres:{$in:["Comedy", "Drama"]}}
{ genres: { $all: ["Comedy", "Drama"] } }
{"imdb.rating" : {$gt: 8.0}, rated:"PG"}
{title: {$regex: '^Dr. Strangelove'}}
30. AT THE END OF THISAT THE END OF THIS EXERCISE 3EXERCISE 3
YOU SHOULD BE ABLE TO...YOU SHOULD BE ABLE TO...
Identify how a query was run using the Explain Plan
Create an index on a collection
See how an index affects query plans
33. EXPLAIN PLANEXPLAIN PLAN
.FIND({"ADDRESS.ZIPCODE": {$GT: '5000'}, CUISINE:.FIND({"ADDRESS.ZIPCODE": {$GT: '5000'}, CUISINE:
'SUSHI'}).SORT({STARS:-1})'SUSHI'}).SORT({STARS:-1})
Not a good result...
ColScan and In-Memory Sort
We need indexes
34. WHAT INDEX TO USE?WHAT INDEX TO USE?
.FIND({"ADDRESS.ZIPCODE": {$GT: '5000'}, CUISINE:.FIND({"ADDRESS.ZIPCODE": {$GT: '5000'}, CUISINE:
'SUSHI'}).SORT({STARS:-1})'SUSHI'}).SORT({STARS:-1})
35. WHAT INDEX TO USE?WHAT INDEX TO USE?
.FIND({"ADDRESS.ZIPCODE": {$GT: '5000'}, CUISINE:.FIND({"ADDRESS.ZIPCODE": {$GT: '5000'}, CUISINE:
'SUSHI'}).SORT({STARS:-1})'SUSHI'}).SORT({STARS:-1})
Naive approach would be
db.createIndex({"address.zipcode":1, "cuisine":1, "stars":1})
36. WHAT INDEX TO USE?WHAT INDEX TO USE?
.FIND({"ADDRESS.ZIPCODE": {$GT: '5000'}, CUISINE:.FIND({"ADDRESS.ZIPCODE": {$GT: '5000'}, CUISINE:
'SUSHI'}).SORT({STARS:-1})'SUSHI'}).SORT({STARS:-1})
Naive approach would be
While better since it does an index scan, still doing an
memory sort since this is a range query, not equality
db.createIndex({"address.zipcode":1, "cuisine":1, "stars":1})
37. WHAT INDEX TO USE?WHAT INDEX TO USE?
.FIND({"ADDRESS.ZIPCODE": {$GT: '5000'}, CUISINE:.FIND({"ADDRESS.ZIPCODE": {$GT: '5000'}, CUISINE:
'SUSHI'}).SORT({STARS:-1})'SUSHI'}).SORT({STARS:-1})
Naive approach would be
While better since it does an index scan, still doing an
memory sort since this is a range query, not equality
Add the index above and compare
versus
db.createIndex({"address.zipcode":1, "cuisine":1, "stars":1})
.find({"address.zipcode": {$gt: '5000'}, cuisine: 'Sushi'}).sort
.find({"address.zipcode": '5000', cuisine: 'Sushi'}).sort({stars
38. ADDING INDEXADDING INDEX
ESR RULEESR RULE
Great rule of thumb
Remove your last index
Remember Equality, Sort, Range
39. ADDING INDEXADDING INDEX
ESR RULEESR RULE
Great rule of thumb
Remove your last index
Remember Equality, Sort, Range
db.createIndex({"cuisine":1, "stars":1, "address.zipcode":1})
41. AT THE END OF THISAT THE END OF THIS EXERCISE 4EXERCISE 4
YOU SHOULD BE ABLE TO...YOU SHOULD BE ABLE TO...
Have a basic understanding of what the aggregation
framework is
Write some basic queries using the aggregation
framework
46. AGG WORKSHOPAGG WORKSHOP
Question Answer
That Are Comedies
Have a rating
Just the title and how many years old
$match {genres:"Comedy"}
47. AGG WORKSHOPAGG WORKSHOP
Question Answer
That Are Comedies
Have a rating
Just the title and how many years old
$match {genres:"Comedy"}
$match {rated:{$exists:true}}
48. AGG WORKSHOPAGG WORKSHOP
Question Answer
That Are Comedies
Have a rating
Just the title and how many years old
$match {genres:"Comedy"}
$match {rated:{$exists:true}}
$project {
_id:0,
title:1,
yearsOld: { $subtract: [2018,"$year"]}
}
49. 1 DEGREE OF KEVIN BACON1 DEGREE OF KEVIN BACON
Stage 1
Stage 2
Stage 3
Stage 4
50. 1 DEGREE OF KEVIN BACON1 DEGREE OF KEVIN BACON
Stage 1
Stage 2
Stage 3
Stage 4
$project {
title:1, actors:1,_id:0
}
55. AT THE END OF THISAT THE END OF THIS EXERCISE 5EXERCISE 5
YOU SHOULD BE ABLE TO...YOU SHOULD BE ABLE TO...
Enable BI Connector on a cluster
Connect to a MongoDB cluster using a SQL CLI or BI
tool like PowerBI
56. ENABLE BI CONNECTORENABLE BI CONNECTOR
HTTPS://DOCS.MONGODB.COM/BI-CONNECTOR/CURRENT/CONNECT/POWERBI/HTTPS://DOCS.MONGODB.COM/BI-CONNECTOR/CURRENT/CONNECT/POWERBI/
64. LET'S MAKE SOME DASHBOARDSLET'S MAKE SOME DASHBOARDS
USE YOUR CLUSTER WITH MOVIES DBUSE YOUR CLUSTER WITH MOVIES DB
OR MY CLUSTER HAS LOTS OF CHOICES...OR MY CLUSTER HAS LOTS OF CHOICES...
66. AT THE END OF THISAT THE END OF THIS EXERCISE 6EXERCISE 6
YOU SHOULD BE ABLE TO...YOU SHOULD BE ABLE TO...
Understand MongoDB Stitch serverless platform
capabilities
Create Stitch triggers on Change Streams, functions, etc
73. AT THE END OF THISAT THE END OF THIS EXERCISE 7EXERCISE 7
YOU SHOULD BE ABLE TO...YOU SHOULD BE ABLE TO...
Register the MongoDB Spark Connector on Azure
Databricks
Write data to MongoDB
Load data from a MongoDB collection
Load data from an aggregation framework pipeline
Run Spark SQL
http://l.gsky.us#!ms sparkhttp://l.gsky.us#!ms spark