MongoDB Atlas & Microsoft Azure

Hands-On Exercises

Solutions Architect @ MongoDB |
Deck & Content |!mdbmsft2018
Registration Link |!mdbmsft2018reg
Click Here For Printable Version

Terminology Check

Exercise 1

MongoDB Atlas & Users

At the end of this Exercise 1 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

Deploy M0 on Azure



Exercise 2

MongoDB Compass & CRUD

At the end of this Exercise 2 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

Connecting to Atlas with Compass

Connecting to Atlas with Compass

Creating a DB & Collection

Importing Data


Connection Strings

If your cluster works, use it, but...

SRV RecordYes on Switch
Auth DBadmin

M001 CRUD: Let's Create...


Schema & Data Types

M001 CRUD: Let's Read...


M001 CRUD: Let's Update...


M001 CRUD: Let's Delete...


M001 CRUD: Find me movies...

From 1987
"Comedy" as one of their genres
"Comedy" as only genre
"Comedy" or "Drama"
{genres:{$in:["Comedy", "Drama"]}}
"Comedy" and "Drama
{ genres: { $all: ["Comedy", "Drama"] } }
IMDB Rating > 8.0 and PG Rating
{"imdb.rating" : {$gt: 8.0}, rated:"PG"}
Whole title of "Dr. Strangelove"
{title: {$regex: '^Dr. Strangelove'}}

Exercise 3

Indexes & Explain Plan

At the end of this Exercise 3 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

Explain Plan

Explain Plan

.find({"address.zipcode": {$gt: '5000'}, cuisine: 'Sushi'}).sort({stars:-1})

  • Not a good result...
  • ColScan and In-Memory Sort
  • We need indexes

What Index To Use?

.find({"address.zipcode": {$gt: '5000'}, cuisine: 'Sushi'}).sort({stars:-1})

  • Naive approach would be
    db.createIndex({"address.zipcode":1, "cuisine":1, "stars":1})
  • While better since it does an index scan, still doing an in-memory sort since this is a range query, not equality
  • Add the index above and compare
    .find({"address.zipcode": {$gt: '5000'}, cuisine: 'Sushi'}).sort({stars:-1})
    .find({"address.zipcode": '5000', cuisine: 'Sushi'}).sort({stars:-1})

Adding Index

ESR Rule

  • Great rule of thumb
  • Remove your last index
  • Remember Equality, Sort, Range
  • db.createIndex({"cuisine":1, "stars":1, "address.zipcode":1})

Exercise 4

Aggregation Framework

At the end of this Exercise 4 you should be able to...

  • Have a basic understanding of what the aggregation framework is
  • Write some basic queries using the aggregation framework

Aggregation Framework

University M121

Aggregation Framework


Agg Workshop

That Are Comedies
$match {genres:"Comedy"}
Have a rating
$match {rated:{$exists:true}}
Just the title and how many years old
$project {
    yearsOld: { $subtract: [2018,"$year"]}

1 Degree of Kevin Bacon

Stage 1
$project {
    title:1, actors:1,_id:0
Stage 2
$graphLookup {
    from: 'movies',
    startWith: "$actors",
    connectFromField: 'actors',
    connectToField: 'actors',
    as: 'foo',
    maxDepth: 1,
    depthField: 'degrees',
    restrictSearchWithMatch: {actors:"Kevin Bacon"}
Stage 3
$project {
Stage 4
$match {

Exercise 5

BI Connector

At the end of this Exercise 5 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

Enable BI Connector

Now We Talk SQL


Configuring ODBC

Configuring ODBC

Let's Make Some Dashboards

Use your cluster with Movies DB

Or my cluster has lots of choices...

Exercise 6

Stitch & Integrations

At the end of this Exercise 6 you should be able to...

  • Understand MongoDB Stitch serverless platform capabilities
  • Create Stitch triggers on Change Streams, functions, etc

Stitch Components

Serverless Scenarios

AppAtlas TechAzure TechLink
Bowling TrackerQuery Anywhere
Trigger Functions
"Instagram"Query Anywhere
Trigger Functions
Web App
Azure Storage
Xamarin App
Cognitive Vision!igsrc
"Tiny URL"WebHooksWeb!linksrc

"Instagram" App


"Instagram" App


Exercise 7

Big Data

At the end of this Exercise 7 you should be able to...!msftspark

  • 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

Download HTML Code!msftspark

Thank You