SlideShare a Scribd company logo
Technical Support Engineer
thomas@10gen.com
Thomas Rückstieß
#MongoDBDays
Building your first app;
an introduction to
MongoDB
What is MongoDB
MongoDB is a ___________
database
• Document
• Open source
• High performance
• Horizontally scalable
• Full featured
Document Database
• Not for .PDF & .DOC files
• A document is essentially an associative array
• Document == JSON object
• Document == PHPArray
• Document == Python Dictionary
• Document == Ruby Hash
• etc
Open Source
• MongoDB is an open source project
• On GitHub
• Licensed under the AGPL
• Commercial licenses available
• Started & sponsored by 10gen
• Contributions welcome
High Performance
• Written in C++
• Extensive use of memory-mapped files
i.e. read-through write-through memory caching.
• Runs nearly everywhere
• Data serialized as BSON (fast parsing)
• Full support for primary & secondary indexes
• Document model = less work
Horizontally Scalable
Full Featured
• Ad Hoc queries
• Real time aggregation
• Rich query capabilities
• Traditionally consistent
• Geospatial features
• Support for most programming languages
• Flexible schema
Database Landscape
http://www.mongodb.org/download
s
Mongo Shell
Document Database
RDBMS MongoDB
Table, View ➜ Collection
Row ➜ Document
Index ➜ Index
Join ➜ Embedded Document
Foreign Key ➜ Reference
Partition ➜ Shard
Terminology
Typical (relational) ERD
MongoDB ERD
http://www.flickr.com/photos/somegeekintn/3484353131/
We will build a library
management application
First step in any application is
Determine your entities
Library Management Application
Entities
• Library Patrons (users)
• Books (catalog)
• Authors
• Publishers
• Categories ??
In a relational based app
We would start by doing
schema design
Relational schema design
• Large ERD Diagrams
• Complex create table statements
• ORMs to map tables to objects
• Tables just to join tables together
• For this simple app we'd have 5 tables and 5 join
tables
• Lots of revisions until we get it just right
In a MongoDB based app
We start building our
app
and let the schema evolve
MongoDB collections
• Users
• Books
• Authors
• Publishers
No common language
so using the shell
Working with MongoDB
user = {
username: 'fred.jones',
first_name: 'fred',
last_name: 'jones’
}
Start with an object
(or array, hash, dict, etc)
> db.users.insert(user)
Insert the record
No collection creation
needed
> db.users.findOne()
{
"_id" : ObjectId("50804d0bd94ccab2da652599"),
"username" : "fred.jones",
"first_name" : "fred",
"last_name" : "jones"
}
Querying for the user
_id
• _id is the primary key in MongoDB
• Automatically indexed
• Automatically created as an ObjectId if not
provided
• Any unique immutable value could be used
ObjectId
• ObjectId is a special 12 byte value
• Guaranteed to be unique across your cluster
• ObjectId("50804d0bd94ccab2da652599")
|-------------||---------||-----||----------|
ts mac pid inc
> 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
> db.author.findOne( { last_name : 'tolkien' } )
{
"_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."
}
Querying for our author
> 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: new Date('21 July 1954'),
}
})
Creating a Book
http://society6.com/PastaSoup/The-Fellowship-of-the-Ring-ZZc_Print/
> db.books.findOne({language: 'english'}, {genre: 1})
{
"_id" : ObjectId("50804391d94ccab2da652598"),
"genre" : [
"fantasy",
"adventure"
]
}
Multiple values per key
> db.books.findOne({genre: 'fantasy'}, {title: 1})
{
"_id" : ObjectId("50804391d94ccab2da652598"),
"title" : "fellowship of the ring, the"
}
Querying for key with
multiple values
Query key with single value or
multiple values the same way.
> db.books.findOne({}, {publication: 1})
{
"_id" : ObjectId("50804ec7d94ccab2da65259a"),
"publication" : {
"name" : "george allen & unwin",
"location" : "London",
"date" : ISODate("1954-07-21T04:00:00Z")
}
}
Nested Values
> db.books.findOne(
{'publication.date' :
{ $lt : new Date('21 June 1960')}
}
)
{
"_id" : ObjectId("50804391d94ccab2da652598"),
"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-21T04:00:00Z")
}
}
Reach into nested values
using dot notation
> db.books.update(
{"_id" : ObjectId("50804391d94ccab2da652598")},
{ $set : {
isbn: '0547928211',
pages: 432
}
})
Update books
True agile development.
Simply change how you work with
the data and the database follows
db.books.findOne()
{
"_id" : ObjectId("50804ec7d94ccab2da65259a"),
"author" : ObjectId("507ffbb1d94ccab2da652597"),
"genre" : [ "fantasy", "adventure" ],
"isbn" : "0395082544",
"language" : "english",
"pages" : 432,
"publication" : {
"name" : "george allen & unwin",
"location" : "London",
"date" : ISODate("1954-07-21T04:00:00Z")
},
"title" : "fellowship of the ring, the"
}
The Updated Book record
> db.books.ensureIndex({title: 1})
> db.books.ensureIndex({genre : 1})
> db.books.ensureIndex({'publication.date': -1})
Creating indexes
> db.books.findOne({title : /^fell/})
{
"_id" : ObjectId("50804ec7d94ccab2da65259a"),
"author" : ObjectId("507ffbb1d94ccab2da652597"),
"genre" : [ "fantasy", "adventure" ],
"isbn" : "0395082544",
"language" : "english",
"pages" : 432,
"publication" : {
"name" : "george allen & unwin",
"location" : "London",
"date" : ISODate("1954-07-21T04:00:00Z")
},
"title" : "fellowship of the ring, the"
}
Querying with RegEx
> db.books.insert({
title: 'two towers, the',
author: ObjectId("507ffbb1d94ccab2da652597"),
language: 'english',
isbn : "034523510X",
genre: ['fantasy', 'adventure'],
pages: 447,
publication: {
name: 'george allen & unwin',
location: 'London',
date: new Date('11 Nov 1954'),
}
})
Adding a few more books
http://society6.com/PastaSoup/The-Two-Towers-XTr_Print/
> db.books.insert({
title: 'return of the king, the',
author: ObjectId("507ffbb1d94ccab2da652597"),
language: 'english',
isbn : "0345248295",
genre: ['fantasy', 'adventure'],
pages: 544,
publication: {
name: 'george allen & unwin',
location: 'London',
date: new Date('20 Oct 1955'),
}
})
Adding a few more books
http://society6.com/PastaSoup/The-Return-of-the-King-Jsc_Print/
> db.books.find(
{ author: ObjectId("507ffbb1d94ccab2da652597")})
.sort({ 'publication.date' : -1})
.limit(1)
{
"_id" : ObjectId("5080d33ed94ccab2da65259d"),
"title" : "return of the king, the",
"author" : ObjectId("507ffbb1d94ccab2da652597"),
"language" : "english",
"isbn" : "0345248295",
"genre" : [ "fantasy", "adventure" ],
"pages" : 544,
"publication" : {
"name" : "george allen & unwin",
"location" : "London",
"date" : ISODate("1955-10-20T04:00:00Z")
}
}
Cursors
page_num = 3; results_per_page = 10; cursor =
db.books.find() .sort({ "publication.date" : -1 })
.skip((page_num - 1) * results_per_page)
.limit(results_per_page);
Paging
> 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
MongoDB Drivers
Real applications are not
built in the shell
MongoDB has native
bindings for over 12
languages
MongoDB drivers
• Official Support for 12 languages
• Community drivers for tons more
• Drivers connect 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)
Next Steps
We've introduced a lot of
concepts here
Schema Design @ 10:35 am
Replication @ 11:30 am
Sharding @ 12:15 pm
Indexing @ 14:30 pm
Technical Support Engineer
thomas@10gen.com
Thomas Rückstieß
#MongoDBDays
Questions?
Fragen?
• Schema Design @ 10:35
• Replication @ 11:30
• Sharding @ 12:15
• Indexing @ 14:30

More Related Content

Similar to buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdf

Building Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDBBuilding Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDB
MongoDB
 
Building Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDBBuilding Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDB
MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Algiers Tech Meetup
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB
 
C# Development (Sam Corder)
C# Development (Sam Corder)C# Development (Sam Corder)
C# Development (Sam Corder)
MongoSF
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDB
rogerbodamer
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
DATAVERSITY
 
Building Your First Application with MongoDB
Building Your First Application with MongoDBBuilding Your First Application with MongoDB
Building Your First Application with MongoDB
MongoDB
 
How to survive in a BASE world
How to survive in a BASE worldHow to survive in a BASE world
How to survive in a BASE world
Uwe Friedrichsen
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
MongoDB
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
Henrik Ingo
 
Schema design
Schema designSchema design
Schema design
christkv
 
Webinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB AppWebinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB App
MongoDB
 
Webinar: Schema Design
Webinar: Schema DesignWebinar: Schema Design
Webinar: Schema Design
MongoDB
 
Building Your First MongoDB Application
Building Your First MongoDB ApplicationBuilding Your First MongoDB Application
Building Your First MongoDB Application
Tugdual Grall
 
MongoDB at GUL
MongoDB at GULMongoDB at GUL
MongoDB at GUL
Israel Gutiérrez
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
christkv
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
Uwe Printz
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling
rogerbodamer
 
MongoDB Mojo: Building a Basic Perl App
MongoDB Mojo: Building a Basic Perl AppMongoDB Mojo: Building a Basic Perl App
MongoDB Mojo: Building a Basic Perl App
Stennie Steneker
 

Similar to buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdf (20)

Building Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDBBuilding Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDB
 
Building Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDBBuilding Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
 
C# Development (Sam Corder)
C# Development (Sam Corder)C# Development (Sam Corder)
C# Development (Sam Corder)
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDB
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
Building Your First Application with MongoDB
Building Your First Application with MongoDBBuilding Your First Application with MongoDB
Building Your First Application with MongoDB
 
How to survive in a BASE world
How to survive in a BASE worldHow to survive in a BASE world
How to survive in a BASE world
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
 
Schema design
Schema designSchema design
Schema design
 
Webinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB AppWebinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB App
 
Webinar: Schema Design
Webinar: Schema DesignWebinar: Schema Design
Webinar: Schema Design
 
Building Your First MongoDB Application
Building Your First MongoDB ApplicationBuilding Your First MongoDB Application
Building Your First MongoDB Application
 
MongoDB at GUL
MongoDB at GULMongoDB at GUL
MongoDB at GUL
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling
 
MongoDB Mojo: Building a Basic Perl App
MongoDB Mojo: Building a Basic Perl AppMongoDB Mojo: Building a Basic Perl App
MongoDB Mojo: Building a Basic Perl App
 

Recently uploaded

Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
Data Hops
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 

Recently uploaded (20)

Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 

buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdf

  • 1. Technical Support Engineer thomas@10gen.com Thomas Rückstieß #MongoDBDays Building your first app; an introduction to MongoDB
  • 3. MongoDB is a ___________ database • Document • Open source • High performance • Horizontally scalable • Full featured
  • 4. Document Database • Not for .PDF & .DOC files • A document is essentially an associative array • Document == JSON object • Document == PHPArray • Document == Python Dictionary • Document == Ruby Hash • etc
  • 5. Open Source • MongoDB is an open source project • On GitHub • Licensed under the AGPL • Commercial licenses available • Started & sponsored by 10gen • Contributions welcome
  • 6. High Performance • Written in C++ • Extensive use of memory-mapped files i.e. read-through write-through memory caching. • Runs nearly everywhere • Data serialized as BSON (fast parsing) • Full support for primary & secondary indexes • Document model = less work
  • 8. Full Featured • Ad Hoc queries • Real time aggregation • Rich query capabilities • Traditionally consistent • Geospatial features • Support for most programming languages • Flexible schema
  • 13. RDBMS MongoDB Table, View ➜ Collection Row ➜ Document Index ➜ Index Join ➜ Embedded Document Foreign Key ➜ Reference Partition ➜ Shard Terminology
  • 17. First step in any application is Determine your entities
  • 18. Library Management Application Entities • Library Patrons (users) • Books (catalog) • Authors • Publishers • Categories ??
  • 19. In a relational based app We would start by doing schema design
  • 20. Relational schema design • Large ERD Diagrams • Complex create table statements • ORMs to map tables to objects • Tables just to join tables together • For this simple app we'd have 5 tables and 5 join tables • Lots of revisions until we get it just right
  • 21. In a MongoDB based app We start building our app and let the schema evolve
  • 22. MongoDB collections • Users • Books • Authors • Publishers
  • 23. No common language so using the shell
  • 25. user = { username: 'fred.jones', first_name: 'fred', last_name: 'jones’ } Start with an object (or array, hash, dict, etc)
  • 26. > db.users.insert(user) Insert the record No collection creation needed
  • 27. > db.users.findOne() { "_id" : ObjectId("50804d0bd94ccab2da652599"), "username" : "fred.jones", "first_name" : "fred", "last_name" : "jones" } Querying for the user
  • 28. _id • _id is the primary key in MongoDB • Automatically indexed • Automatically created as an ObjectId if not provided • Any unique immutable value could be used
  • 29. ObjectId • ObjectId is a special 12 byte value • Guaranteed to be unique across your cluster • ObjectId("50804d0bd94ccab2da652599") |-------------||---------||-----||----------| ts mac pid inc
  • 30. > 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
  • 31. > db.author.findOne( { last_name : 'tolkien' } ) { "_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." } Querying for our author
  • 32. > 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: new Date('21 July 1954'), } }) Creating a Book http://society6.com/PastaSoup/The-Fellowship-of-the-Ring-ZZc_Print/
  • 33. > db.books.findOne({language: 'english'}, {genre: 1}) { "_id" : ObjectId("50804391d94ccab2da652598"), "genre" : [ "fantasy", "adventure" ] } Multiple values per key
  • 34. > db.books.findOne({genre: 'fantasy'}, {title: 1}) { "_id" : ObjectId("50804391d94ccab2da652598"), "title" : "fellowship of the ring, the" } Querying for key with multiple values Query key with single value or multiple values the same way.
  • 35. > db.books.findOne({}, {publication: 1}) { "_id" : ObjectId("50804ec7d94ccab2da65259a"), "publication" : { "name" : "george allen & unwin", "location" : "London", "date" : ISODate("1954-07-21T04:00:00Z") } } Nested Values
  • 36. > db.books.findOne( {'publication.date' : { $lt : new Date('21 June 1960')} } ) { "_id" : ObjectId("50804391d94ccab2da652598"), "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-21T04:00:00Z") } } Reach into nested values using dot notation
  • 37. > db.books.update( {"_id" : ObjectId("50804391d94ccab2da652598")}, { $set : { isbn: '0547928211', pages: 432 } }) Update books True agile development. Simply change how you work with the data and the database follows
  • 38. db.books.findOne() { "_id" : ObjectId("50804ec7d94ccab2da65259a"), "author" : ObjectId("507ffbb1d94ccab2da652597"), "genre" : [ "fantasy", "adventure" ], "isbn" : "0395082544", "language" : "english", "pages" : 432, "publication" : { "name" : "george allen & unwin", "location" : "London", "date" : ISODate("1954-07-21T04:00:00Z") }, "title" : "fellowship of the ring, the" } The Updated Book record
  • 39. > db.books.ensureIndex({title: 1}) > db.books.ensureIndex({genre : 1}) > db.books.ensureIndex({'publication.date': -1}) Creating indexes
  • 40. > db.books.findOne({title : /^fell/}) { "_id" : ObjectId("50804ec7d94ccab2da65259a"), "author" : ObjectId("507ffbb1d94ccab2da652597"), "genre" : [ "fantasy", "adventure" ], "isbn" : "0395082544", "language" : "english", "pages" : 432, "publication" : { "name" : "george allen & unwin", "location" : "London", "date" : ISODate("1954-07-21T04:00:00Z") }, "title" : "fellowship of the ring, the" } Querying with RegEx
  • 41. > db.books.insert({ title: 'two towers, the', author: ObjectId("507ffbb1d94ccab2da652597"), language: 'english', isbn : "034523510X", genre: ['fantasy', 'adventure'], pages: 447, publication: { name: 'george allen & unwin', location: 'London', date: new Date('11 Nov 1954'), } }) Adding a few more books http://society6.com/PastaSoup/The-Two-Towers-XTr_Print/
  • 42. > db.books.insert({ title: 'return of the king, the', author: ObjectId("507ffbb1d94ccab2da652597"), language: 'english', isbn : "0345248295", genre: ['fantasy', 'adventure'], pages: 544, publication: { name: 'george allen & unwin', location: 'London', date: new Date('20 Oct 1955'), } }) Adding a few more books http://society6.com/PastaSoup/The-Return-of-the-King-Jsc_Print/
  • 43. > db.books.find( { author: ObjectId("507ffbb1d94ccab2da652597")}) .sort({ 'publication.date' : -1}) .limit(1) { "_id" : ObjectId("5080d33ed94ccab2da65259d"), "title" : "return of the king, the", "author" : ObjectId("507ffbb1d94ccab2da652597"), "language" : "english", "isbn" : "0345248295", "genre" : [ "fantasy", "adventure" ], "pages" : 544, "publication" : { "name" : "george allen & unwin", "location" : "London", "date" : ISODate("1955-10-20T04:00:00Z") } } Cursors
  • 44. page_num = 3; results_per_page = 10; cursor = db.books.find() .sort({ "publication.date" : -1 }) .skip((page_num - 1) * results_per_page) .limit(results_per_page); Paging
  • 45. > 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. Real applications are not built in the shell
  • 48. MongoDB has native bindings for over 12 languages
  • 49.
  • 50.
  • 51. MongoDB drivers • Official Support for 12 languages • Community drivers for tons more • Drivers connect 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)
  • 53. We've introduced a lot of concepts here
  • 54. Schema Design @ 10:35 am
  • 58. Technical Support Engineer thomas@10gen.com Thomas Rückstieß #MongoDBDays Questions? Fragen? • Schema Design @ 10:35 • Replication @ 11:30 • Sharding @ 12:15 • Indexing @ 14:30