3. 3
• Document
• Open source
• High performance
• Horizontally scalable
• Full featured
MongoDB is a __________ database
4. 4
• Not for .PDF & .DOC files
• A document is essentially an associative array
• Document == JSON object
• Document == PHP Array
• Document == Python Dict
• Document == Ruby Hash
• Document == C# BsonDocument object model
• etc
Document Database
5. 5
• MongoDB is an open source project
• On GitHub
• Licensed under the AGPL
• Started & sponsored by MongoDB, Inc
• Commercial licenses available
• Contributions welcome
Open Source
7. 7
• Written in C++
• Runs nearly everywhere
• Extensive use of memory-mapped files
i.e. read-through write-through memory caching.
• Data serialized as BSON (fast parsing)
• Full support for primary & secondary indexes
• Document model = less work
High Performance
8. 8
• Ad Hoc queries
• Rich query capabilities
• Geospatial features
• Real time aggregation
• Eventually consistent
• Support for many programming languages
• Flexible schema
Full Featured
24. 24
> var user = {
username : "fred.jones",
first_name : "fred",
last_name : "jones"
}
Start with an Object
(or array, hash, dict, etc)
25. 25
> use library
> db.users.insert(user)
Insert the Record
No database or collection creation needed
26. 26
> db.users.findOne()
{
_id : ObjectId("50804d0bd94ccab2da652599"),
username : "fred.jones",
first_name : "fred",
last_name : "jones"
}
Querying for the user
27. 27
• _id is the primary key in MongoDB
• Automatically created as an ObjectId if not
provided
• Any unique immutable value could be used
• Automatically indexed
_id
28. 28
• ObjectId is a special 12 byte value
• Guaranteed to be unique across your cluster
• ObjectId("50804d0bd94ccab2da652599")
ObjectId
Timestamp Machine Pid Increment
50804d0b d94cca b2da 652599
29. 29
> db.author.insert({
first_name : "j.r.r.",
last_name : "tolkien",
bio : "J.R.R. Tolkien (1892.1973), beloved
throughout the world as the creator of The Hobbit and
The Lord of the Rings, was a professor of Anglo-Saxon
at Oxford, a fellow of Pembroke College, and a fellow
of Merton College until his retirement in 1959. His
chief interest was the linguistic aspects of the early
English written tradition, but even as he studied
these classics he was creating a set of his own."
})
Creating an Author
30. 30
> db.books.insert({
title : "fellowship of the ring, the",
author : ObjectID("507ffbb1d94ccab2da652597"),
language : "english",
genre : [ "fantasy", "adventure" ],
publication : {
name : "george allen & unwin",
location : "London",
date : ISODate("1954-07-21T00:00:00Z")
}
})
Creating a Book
34. 34
> db.books.update(
{ _id : ObjectID("50804391d94ccab2da652598") },
{ $set : {
isbn : "0547928211",
pages : 432
}}
)
True agile development.
Simply Change how you work with the
data and the database follows
Update Books
40. 40
> var page_num = 3;
> var results_per_page = 10;
> var cursor = db.books.find()
.sort({ publication_date : -1 })
.skip((page_num – 1) * results_per_page)
.limit(results_per_page);
Paging
41. 41
> var book = db.books.findOne(
{ title : "return of the king, the" })
> db.author.findOne({ _id : book.author })
{
"_id" : ObjectId("507ffbb1d94ccab2da652597"),
"first_name" : "j.r.r.",
"last_name" : "tolkien",
"bio" : "J.R.R. Tolkien (1892.1973), beloved throughout
the world as the creator of The Hobbit and The Lord of the
Rings, was a professor of Anglo-Saxon at Oxford, a fellow of
Pembroke College, and a fellow of Merton College until his
retirement in 1959. His chief interest was the linguistic
aspects of the early English written tradition, but even as
he studied these classics he was creating a set of his own."
}
Finding Author by Book
47. 47
• Official Support for 12 languages
• Community drivers for many more
• Drivers connect applications to mongo servers
• Drivers translate BSON into native types
• mongo shell is not a driver, but works like one in some ways
• Installed using typical means (npm, pecl, gem, pip, nuget)
MongoDB Drivers
51. MongoDB World
New York City, June 23-25
Save 25% with Drivers25
Register at world.mongodb.com
See how Cisco, Stripe, Carfax, Expedia and
others are engineering the next generation of
data with MongoDB
52. MongoDB World
New York City, June 23-25
See what’s next in MongoDB including
• MongoDB 2.6
• Sharding
• Replication
• Aggregation
Save 25% with Drivers25
world.mongodb.com