Your SlideShare is downloading. ×
0
The Hows and Whys of
MongoDB
27 May 2014
Everything is at:	

http://bitly.com/bundles/rockncoder/2
Who am I?
Hi, I am Troy. I have fun as a full stack programmer. I
develop using ASP.NET MVC or Node.js on the backend
and ...
Free mobile tutorials with source
code @ therockncoder.blogspot.com
Want more? Follow me, new tutorials are
announced on Twitter first:
@therockncoder
Source code for my tutorials hosted on
GitHub @
https://github.com/Rockncoder
Check out my videos:
www.youtube.com/rockncoder
MongoDB 9 to 5
• Two day intensive training	

• July 19th & 26th	

• 9 AM - 5 PM	

• ITT Technical Institute,Torrance, CA
Agenda
• Introduction to
MongoDB	

• The MongoDB Shell	

• Using MongoDB	

• Advanced MongoDB	

• MongoDB Tools	

• To Mon...
Introduction to
MongoDB
What is MongoDB?
• Cross-platform document database	

• Developed by MongoDB Inc in 2007	

• Production ready since March ...
Top DB-Engines
• Oracle	

• MySQL	

• MS SQL Server	

• PostgreSQL	

• MongoDB
!
• DB2	

• MS Access	

• SQLite	

• Cassan...
Who Uses It?
• Craigslist	

• eBay	

• Foursquare	

• SourceForge	

• Viacom	

• Expedia	

• Parse	

• LinkedIn	

• Medtro...
Why?
• Document Database	

• High Performance	

• High Availability	

• Easy Scalability
What is a Document?
• An ordered set of keys and values	

• like JavaScript objects	

• no duplicate keys allowed	

• type...
What’s Wrong with
SQL?
• SQL was created by Edgar F. Codd in 1969	

• OracleV2 introduced in 1979	

• MS SQL Server introd...
A Contact Manager
• first name	

• last name	

• home address	

• work address	

• mobile phone	

• home phone
In SQL
• Person table	

• Address table	

• Phone number table	

• Joins necessary to retrieve
In MongoDB
• One document holds it all	

• Including the arrays	

• No joins necessary
SQL MongoDB
row document
table collection
database database
joins none
transactions none
Installation
• The current version is 2.6.1	

• Downloads available for Windows, Linux,
Mac OSX, and Solaris	

• 64-bit fo...
Windows
• Download MongoDB	

• Unzip the file	

• Move it, if necessary	

• Set up the MongoDB environment	

• Start MongoD...
Mac OS X
• The best way is to use Homebrew	

• brew update	

• brew install mongo
The MongoDB Shell
The MongoDB Shell
• Allows interactions with a MongoDB
instance	

• A full-featured JavaScript interpreter	

• Allows mult...
Shell Helpers
• use foo - db.getSisterDB(“foo”)	

• show dbs - db.getMongo().getDBs()	

• show collections -
db.getCollect...
CRUD in the Shell
• Create = insert	

• Read = find/findOne	

• Update = update	

• Delete = remove
BSON not JSON
• MongoDB uses its own variant of JSON	

• Called Binary JSON or BSON	

• Efficiency	

• Traversability	

• P...
Using MongoDB
MongoDB in Node.js
MongoDB in Android
MongoDB in C#
Misunderstandings
• It is schema-less 	

• You don’t need to design db	

• You should mix types
Advanced MongoDB
Performance
• Indexing	

• Query Optimization	

• Profiler
Indexing
• Indexes should support queries	

• Use indexes to sort queries	

• Indexes should fit into RAM	

• Queries shoul...
Query Optimization
• Improves read operations by reducing data
that the query needs to process
Profiler
• Collects data about MongoDB database
commands	

• Enabled per-database or per-instance basis	

• Profile level is...
Stats
• db.stats()	

• Statistics that reflect the use of a single DB	

• Identifies:	

• the current database	

• the numbe...
Replication
• Keeps identical copies of data on multiple
servers	

• Set up by creating a replica set	

• A replica set is...
Backup
• mongodump - command line tool	

• You must have backup and read privileges	

• No arguments connects to the local...
Restore
• mongorestore --port <port number>
<path to the backup>	

• Can restore to a running instance or to the
files	

• ...
Sharding
• Process of splitting data up across machines	

• Manual sharding can be with most database	

• MongoDB has auto...
MongoDB Tools
Tools
• MongoDB Shell (built-in)	

• MongoDB Web Site (built-in)	

• Robomongo (Mac, PC, Linux)	

• http://mongodb-tools.c...
To MongoDB or not to
MongoDB
Not to MongoDB
• Transactions are needed	

• You are happy with what you have	

• You have have
To MongoDB
• You do a lot of non-transactional writes	

• You need to grow wide	

• You work with location based data	

• ...
MongoDB as a Service
• MongoHQ	

• MongoLab	

• MongoDirector	

• ObjectRocket, (Rackspace)
Summary
• MongoDB is an open-source document
database	

• It features JSON-style documents with
dynamic schemas	

• In ord...
Everything is at:	

http://bitly.com/bundles/rockncoder/2
Upcoming SlideShare
Loading in...5
×

The Hows and Whys of MongoDB

428

Published on

Want to get started with MongoDB? Here is a quick intro the major features of the most popular NoSQL database.

Published in: Software, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
428
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "The Hows and Whys of MongoDB"

  1. 1. The Hows and Whys of MongoDB 27 May 2014
  2. 2. Everything is at: http://bitly.com/bundles/rockncoder/2
  3. 3. Who am I? Hi, I am Troy. I have fun as a full stack programmer. I develop using ASP.NET MVC or Node.js on the backend and the web or mobile up front. ! I can be reached at: rockncoder@gmail.com
  4. 4. Free mobile tutorials with source code @ therockncoder.blogspot.com
  5. 5. Want more? Follow me, new tutorials are announced on Twitter first: @therockncoder
  6. 6. Source code for my tutorials hosted on GitHub @ https://github.com/Rockncoder
  7. 7. Check out my videos: www.youtube.com/rockncoder
  8. 8. MongoDB 9 to 5 • Two day intensive training • July 19th & 26th • 9 AM - 5 PM • ITT Technical Institute,Torrance, CA
  9. 9. Agenda • Introduction to MongoDB • The MongoDB Shell • Using MongoDB • Advanced MongoDB • MongoDB Tools • To MongoDB or not to MongoDB • Summary • Questions
  10. 10. Introduction to MongoDB
  11. 11. What is MongoDB? • Cross-platform document database • Developed by MongoDB Inc in 2007 • Production ready since March 2010 • Free and open-source • The most popular NoSQL database
  12. 12. Top DB-Engines • Oracle • MySQL • MS SQL Server • PostgreSQL • MongoDB ! • DB2 • MS Access • SQLite • Cassandra • Sybase ASE
  13. 13. Who Uses It? • Craigslist • eBay • Foursquare • SourceForge • Viacom • Expedia • Parse • LinkedIn • Medtronic • eHarmony • CERN • and more
  14. 14. Why? • Document Database • High Performance • High Availability • Easy Scalability
  15. 15. What is a Document? • An ordered set of keys and values • like JavaScript objects • no duplicate keys allowed • type and case sensitive • field order is not important or guaranteed
  16. 16. What’s Wrong with SQL? • SQL was created by Edgar F. Codd in 1969 • OracleV2 introduced in 1979 • MS SQL Server introduced in 1989 • Today most languages are object-oriented • SQL is column and row oriented
  17. 17. A Contact Manager • first name • last name • home address • work address • mobile phone • home phone
  18. 18. In SQL • Person table • Address table • Phone number table • Joins necessary to retrieve
  19. 19. In MongoDB • One document holds it all • Including the arrays • No joins necessary
  20. 20. SQL MongoDB row document table collection database database joins none transactions none
  21. 21. Installation • The current version is 2.6.1 • Downloads available for Windows, Linux, Mac OSX, and Solaris • 64-bit for all systems, 32-bit for Windows & Linux • 32-bit is not recommends except for learning
  22. 22. Windows • Download MongoDB • Unzip the file • Move it, if necessary • Set up the MongoDB environment • Start MongoDB • Connect to MongoDB
  23. 23. Mac OS X • The best way is to use Homebrew • brew update • brew install mongo
  24. 24. The MongoDB Shell
  25. 25. The MongoDB Shell • Allows interactions with a MongoDB instance • A full-featured JavaScript interpreter • Allows multiple line input
  26. 26. Shell Helpers • use foo - db.getSisterDB(“foo”) • show dbs - db.getMongo().getDBs() • show collections - db.getCollectionNames()
  27. 27. CRUD in the Shell • Create = insert • Read = find/findOne • Update = update • Delete = remove
  28. 28. BSON not JSON • MongoDB uses its own variant of JSON • Called Binary JSON or BSON • Efficiency • Traversability • Performance
  29. 29. Using MongoDB
  30. 30. MongoDB in Node.js
  31. 31. MongoDB in Android
  32. 32. MongoDB in C#
  33. 33. Misunderstandings • It is schema-less • You don’t need to design db • You should mix types
  34. 34. Advanced MongoDB
  35. 35. Performance • Indexing • Query Optimization • Profiler
  36. 36. Indexing • Indexes should support queries • Use indexes to sort queries • Indexes should fit into RAM • Queries should ensure selectivity
  37. 37. Query Optimization • Improves read operations by reducing data that the query needs to process
  38. 38. Profiler • Collects data about MongoDB database commands • Enabled per-database or per-instance basis • Profile level is configurable (0, 1, or 2)
  39. 39. Stats • db.stats() • Statistics that reflect the use of a single DB • Identifies: • the current database • the number of indexes • the file size
  40. 40. Replication • Keeps identical copies of data on multiple servers • Set up by creating a replica set • A replica set is a group of servers with one primary • If primary crash, secondaries elect a new one
  41. 41. Backup • mongodump - command line tool • You must have backup and read privileges • No arguments connects to the local DB • —db, limits the database • —collection, limits the collections • —oplog, makes snapshots possible
  42. 42. Restore • mongorestore --port <port number> <path to the backup> • Can restore to a running instance or to the files • —oplogReplay, • —filter, allows restore only if filter is true
  43. 43. Sharding • Process of splitting data up across machines • Manual sharding can be with most database • MongoDB has autosharding • Nonetheless it is difficult to configure
  44. 44. MongoDB Tools
  45. 45. Tools • MongoDB Shell (built-in) • MongoDB Web Site (built-in) • Robomongo (Mac, PC, Linux) • http://mongodb-tools.com/
  46. 46. To MongoDB or not to MongoDB
  47. 47. Not to MongoDB • Transactions are needed • You are happy with what you have • You have have
  48. 48. To MongoDB • You do a lot of non-transactional writes • You need to grow wide • You work with location based data • You need high availability
  49. 49. MongoDB as a Service • MongoHQ • MongoLab • MongoDirector • ObjectRocket, (Rackspace)
  50. 50. Summary • MongoDB is an open-source document database • It features JSON-style documents with dynamic schemas • In order to gain performance, it sacrifices reliability
  51. 51. Everything is at: http://bitly.com/bundles/rockncoder/2
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×