An Introduction to Document
Databases with MongoDB
Brett Gray, Senior Consulting Engineer, MongoDB
Why am I here?
About a decade ago, three guys with a lot of industry experience got together and thought
“There must be a better way”. A better way to store data, that was more intuitive and more
natural…
Agenda
What is MongoDB?
Document Model
Query Language
Resiliency
MongoDB Ecosystem
Demo
Brett Gray
Senior Consulting Engineer
About Me
I’m a Senior Consulting Engineer in the Professional Services team at MongoDB.
In a previous life, I served on Submarines in the Royal Australian Navy and was a Principal Engineer at
Puppet…….I also have a Graduate Diploma of Brewing.
What is MongoDB?
What is MongoDB?
MongoDB is a cross-platform and open-source document-oriented general purpose database. As a document
database, MongoDB doesn’t use table-based structure, rather it uses JSON-like documents that have dynamic
schemas which it calls BSON.
Please keep in mind that NoSQL does not mean no relationships!
What is MongoDB?
Server written in C++ and C
Tools written in C++, C, Go, Java, and JavaScript
Binary packages are available for download at mongodb.com/downloads
Source code for the server is available at github.com/mongodb
Ready for deployment in the cloud, on VMs or on bare metal
What is MongoDB?
MongoDB was written to make it simple to store data.
• {"Key": "Value"}
Documents map naturally to common data structures in most popular programming languages
Schemas are dynamic. There’s no need for expensive migrations.
As new data is encountered, just store it. If the shape of data needs to change, then change it.
We are schema-flexible, but it is important to be consistent
What is MongoDB?
MongoDB is an ecosystem of products, including a database, visual data explorer, platform, and analytics tools to
make it easier than ever to develop your applications.
Document Model
Document Model
Not just key-
valueMongoDB’s document model is not just a key-value
store.
Rich document composition is possible, and
encouraged.
Store embedded objects, arrays, rich data types, and
more.
{
"title": "The Martian",
"year": 2015,
"runtime": 130,
"released": ISODate("2015-10-
02T00:00:00Z"),
"cast": [
"Kate Mara",
"Matt Damon",
"Jessica Chastain",
"Kristen Wiig"
]
}
Document Model
MongoDB RDBMS
Database Database
Collection Table
Index Index
Document Row
Field Column
Embedding, Linking, $lookup Join
…using a SQL Model
…using a Document Model
Document Model
It’s a natural way to think about data, and maps incredibly well to patterns we know and common types and
structures we use daily.
The schema should be modelled from how you access your data.
As highlighted, the schema is flexible, but you can use schema validation within in your application and within the
database to enforce your schema.
Query Language
MQL and Aggregation
Query Language
CREATE TABLE movies (
id MEDIUMINT NOT NULL
AUTO_INCREMENT,
title Varchar(30),
year Number,
rating Number,
PRIMARY KEY (id)
)
db.createCollection("movies")
Query Language
INSERT INTO movies(title,
year, rating) VALUES ("The
Shawshank Redemption", 10,
1994)
db.movies.insertOne({title:
"The Shawshank Redemption",
year: 1994, rating: 10})
Query Language
ALTER TABLE movies ADD cast
ARRAY
UPDATE movies SET cast =
["Morgan Freeman", "Tim
Robbins"] WHERE title = "The
Shawshank Redemption"
db.movies.updateOne(
{title: "The Shawshank
Redemption"},
{$set: { "cast": ["Morgan
Freeman", "Tim Robbins" ] } }
)
Query Language
ALTER TABLE movies ADD cast
ARRAY
UPDATE movies SET cast =
["Morgan Freeman", "Tim
Robbins"] WHERE title = "The
Shawshank Redemption"
db.movies.updateOne(
{title: "The Shawshank
Redemption"},
{$set: { "cast": ["Morgan
Freeman", "Tim Robbins" ] } }
)
Query Language
SELECT * FROM movies
SELECT * FROM movies WHERE
rating > 7
SELECT * FROM movies WHERE
rating > 7 LIMIT 1
SELECT * FROM movies WHERE
rating > 7 AND year > 1990
??
db.movies.find()
db.movies.find({rating: { $gt:
7 }})
db.movies.findOne({rating: {
$gt: 7 }}).limit(1)
db.movies.find({rating: { $gt:
7 }, year: { $gt: 1990 } })
db.movies.find({cast: "Morgan
Freeman"})
Query Language
CREATE INDEX
idx_movie_rating_desc ON
movies(rating DESC)
db.movies.createIndex({ rating:
-1 })
Query Language - Performance
Indexes support the efficient execution of queries in MongoDB.
Many index types
• Single Field
• Multikey
• Text
• Geospatial
• Hashed
• Compound
Query Language - Aggregation
A framework for data aggregation modelled on the concept of data processing pipelines.
Documents enter a multi-stage pipeline that transforms the documents into aggregated results.
Reduce the CPU cycles in processing your app, let MongoDB handle aggregation.
Results produced from aggregation lower in total byte size of your data, saving bandwidth.
Query Language - Aggregation
A framework for data aggregation modeled on the concept of data processing pipelines.
Documents enter a multi-stage pipeline that transforms the documents into aggregated results.
Query Language
Expressive
Intuitive
Logical
Resiliency
Resiliency – The Replica Set
Resiliency – The Replica Set
Your application talks to MongoDB through the
driver, which is constantly monitoring your replica
set health.
Internally, the replica set is monitoring health as
well, ready to react in case of emergency.
Resiliency - Reacting
Resiliency – The Replica Set
Your application talks to MongoDB through the
driver, which is constantly monitoring your replica
set health.
Internally, the replica set is monitoring health as
well, ready to react in case of emergency.
MongoDB Ecosystem
MongoDB Ecosystem
Compass
Atlas
Stitch
Charts
Ops Manager
Cloud Manager
Ecosystem - Compass
MongoDB’s GUI to explore and interact with your data.
Ecosystem - Atlas
Atlas – Infrastructure
Infrastructure managed by MongoDB
Updated with zero downtime
Available in AWS, GCP, and Azure
Atlas – Built in Security
TLS/SSL
Authentication and Authorization
IP Whitelists
User roles
VPC Peering (AWS and GCP)
AES-256 hardware encryption
Atlas – Graphs and Metrics
MongoDB
Hardware
Utilization
Performance
Atlas – Real Time Performance
Atlas – So Much More
Monitoring and Alerting
• Supports Third-Party integration
• Webhooks
• Email
• SMS
• PagerDuty
• Slack
Live Migration
Backups and Recovery
BI Connector
Ecosystem - Stitch
Ecosystem - Charts
Live Coding
Typing accuracy and mental faculty guaranteed to reduce by 37%!
Thank You!
MongoDB.local Sydney: An Introduction to Document Databases with MongoDB

MongoDB.local Sydney: An Introduction to Document Databases with MongoDB

  • 2.
    An Introduction toDocument Databases with MongoDB Brett Gray, Senior Consulting Engineer, MongoDB
  • 3.
    Why am Ihere? About a decade ago, three guys with a lot of industry experience got together and thought “There must be a better way”. A better way to store data, that was more intuitive and more natural…
  • 4.
    Agenda What is MongoDB? DocumentModel Query Language Resiliency MongoDB Ecosystem Demo
  • 5.
  • 6.
    About Me I’m aSenior Consulting Engineer in the Professional Services team at MongoDB. In a previous life, I served on Submarines in the Royal Australian Navy and was a Principal Engineer at Puppet…….I also have a Graduate Diploma of Brewing.
  • 7.
  • 8.
    What is MongoDB? MongoDBis a cross-platform and open-source document-oriented general purpose database. As a document database, MongoDB doesn’t use table-based structure, rather it uses JSON-like documents that have dynamic schemas which it calls BSON. Please keep in mind that NoSQL does not mean no relationships!
  • 9.
    What is MongoDB? Serverwritten in C++ and C Tools written in C++, C, Go, Java, and JavaScript Binary packages are available for download at mongodb.com/downloads Source code for the server is available at github.com/mongodb Ready for deployment in the cloud, on VMs or on bare metal
  • 10.
    What is MongoDB? MongoDBwas written to make it simple to store data. • {"Key": "Value"} Documents map naturally to common data structures in most popular programming languages Schemas are dynamic. There’s no need for expensive migrations. As new data is encountered, just store it. If the shape of data needs to change, then change it. We are schema-flexible, but it is important to be consistent
  • 11.
    What is MongoDB? MongoDBis an ecosystem of products, including a database, visual data explorer, platform, and analytics tools to make it easier than ever to develop your applications.
  • 12.
  • 13.
  • 14.
    Not just key- valueMongoDB’sdocument model is not just a key-value store. Rich document composition is possible, and encouraged. Store embedded objects, arrays, rich data types, and more. { "title": "The Martian", "year": 2015, "runtime": 130, "released": ISODate("2015-10- 02T00:00:00Z"), "cast": [ "Kate Mara", "Matt Damon", "Jessica Chastain", "Kristen Wiig" ] }
  • 15.
    Document Model MongoDB RDBMS DatabaseDatabase Collection Table Index Index Document Row Field Column Embedding, Linking, $lookup Join
  • 16.
  • 17.
  • 18.
    Document Model It’s anatural way to think about data, and maps incredibly well to patterns we know and common types and structures we use daily. The schema should be modelled from how you access your data. As highlighted, the schema is flexible, but you can use schema validation within in your application and within the database to enforce your schema.
  • 19.
  • 20.
    Query Language CREATE TABLEmovies ( id MEDIUMINT NOT NULL AUTO_INCREMENT, title Varchar(30), year Number, rating Number, PRIMARY KEY (id) ) db.createCollection("movies")
  • 21.
    Query Language INSERT INTOmovies(title, year, rating) VALUES ("The Shawshank Redemption", 10, 1994) db.movies.insertOne({title: "The Shawshank Redemption", year: 1994, rating: 10})
  • 22.
    Query Language ALTER TABLEmovies ADD cast ARRAY UPDATE movies SET cast = ["Morgan Freeman", "Tim Robbins"] WHERE title = "The Shawshank Redemption" db.movies.updateOne( {title: "The Shawshank Redemption"}, {$set: { "cast": ["Morgan Freeman", "Tim Robbins" ] } } )
  • 23.
    Query Language ALTER TABLEmovies ADD cast ARRAY UPDATE movies SET cast = ["Morgan Freeman", "Tim Robbins"] WHERE title = "The Shawshank Redemption" db.movies.updateOne( {title: "The Shawshank Redemption"}, {$set: { "cast": ["Morgan Freeman", "Tim Robbins" ] } } )
  • 24.
    Query Language SELECT *FROM movies SELECT * FROM movies WHERE rating > 7 SELECT * FROM movies WHERE rating > 7 LIMIT 1 SELECT * FROM movies WHERE rating > 7 AND year > 1990 ?? db.movies.find() db.movies.find({rating: { $gt: 7 }}) db.movies.findOne({rating: { $gt: 7 }}).limit(1) db.movies.find({rating: { $gt: 7 }, year: { $gt: 1990 } }) db.movies.find({cast: "Morgan Freeman"})
  • 25.
    Query Language CREATE INDEX idx_movie_rating_descON movies(rating DESC) db.movies.createIndex({ rating: -1 })
  • 26.
    Query Language -Performance Indexes support the efficient execution of queries in MongoDB. Many index types • Single Field • Multikey • Text • Geospatial • Hashed • Compound
  • 27.
    Query Language -Aggregation A framework for data aggregation modelled on the concept of data processing pipelines. Documents enter a multi-stage pipeline that transforms the documents into aggregated results. Reduce the CPU cycles in processing your app, let MongoDB handle aggregation. Results produced from aggregation lower in total byte size of your data, saving bandwidth.
  • 28.
    Query Language -Aggregation A framework for data aggregation modeled on the concept of data processing pipelines. Documents enter a multi-stage pipeline that transforms the documents into aggregated results.
  • 29.
  • 30.
  • 31.
    Resiliency – TheReplica Set
  • 32.
    Resiliency – TheReplica Set Your application talks to MongoDB through the driver, which is constantly monitoring your replica set health. Internally, the replica set is monitoring health as well, ready to react in case of emergency.
  • 33.
  • 34.
    Resiliency – TheReplica Set Your application talks to MongoDB through the driver, which is constantly monitoring your replica set health. Internally, the replica set is monitoring health as well, ready to react in case of emergency.
  • 35.
  • 36.
  • 37.
    Ecosystem - Compass MongoDB’sGUI to explore and interact with your data.
  • 38.
  • 39.
    Atlas – Infrastructure Infrastructuremanaged by MongoDB Updated with zero downtime Available in AWS, GCP, and Azure
  • 40.
    Atlas – Builtin Security TLS/SSL Authentication and Authorization IP Whitelists User roles VPC Peering (AWS and GCP) AES-256 hardware encryption
  • 41.
    Atlas – Graphsand Metrics MongoDB Hardware Utilization Performance
  • 42.
    Atlas – RealTime Performance
  • 43.
    Atlas – SoMuch More Monitoring and Alerting • Supports Third-Party integration • Webhooks • Email • SMS • PagerDuty • Slack Live Migration Backups and Recovery BI Connector
  • 44.
  • 45.
  • 46.
    Live Coding Typing accuracyand mental faculty guaranteed to reduce by 37%!
  • 47.

Editor's Notes

  • #9 We have community and enterprise editions Works on Linux 64bit, Windows 64bit, and macOS Open-source, you can find the source code on Github Document-oriented….we go into this further. Uses BSON, which is binary-enclosed presentation of JSON that provides further data types, ordering etc There are still relationships!
  • #11 Think about hashtables, dictionaries etc
  • #12 Mongodb Compass Charts BI Connector
  • #17 Basic Relational schema…….how many tables do I need to join to see a what makes and models of cars a person owns? Point out that a multiple people can belong to multiple professions. And multiple people can own multiple cars (joint ownership) This gets compared to a document schema in the next slide
  • #22 Notice the order of our insert is different….because we do not care!
  • #23 Some RDMS do have array support The next slide just shows that some RDBMS will not handle ARRAYs (or objects for that matter)
  • #28 Using Aussie spelling here…. The conveyor belt image is next
  • #29 Output of one stage is the input for the next stage Use Compass to see examples of how to use Aggregation
  • #31 Highlight that people have different meanings for High Availability and Resiliency……..and it is not sharding Resiliency, not scaling!