1 of 34

Slide Notes

DownloadGo Live

MongoDB in a nutshell

Published on Nov 18, 2015

No Description

PRESENTATION OUTLINE

MongoDB in a nutshell

for Developers
Photo by steffenz

Untitled Slide

MongoDB vs RDBMS

Photo by Will Cyr

Untitled Slide

Untitled Slide

Key features

High Performance

  • Support for embedded data models reduces I/O activity on database system
  • Indexes support faster queries and can include keys from embedded documents and arrays

High Availability

  • MongoDB’s replication facility, called replica sets, provide: - automatic failover - data redundancy

High Availability

  • MongoDB’s replication facility, called replica sets, provide: - automatic failover - data redundancy

Replication

  • Electing primary node
  • Roles: primary, secondaries, arbiter
  • Oplog, failover after primary down
  • Write concern (w:majority, j)

Untitled Slide

Demo time!

Automatic Scaling

  • Automatic sharding distributes data across a cluster of machines
  • Replica sets can provide eventually-consistent reads for low-latency high throughput deployments

Sharding

  • Vertical scaling vs. sharding
  • Chunks
  • Partitioning Strategies: - range based - hash based

Untitled Slide

Chunks strategies

Untitled Slide

Data model

Photo by arisexpress

Embedding

  • 1:1 or 1:many relationships
  • Better performance for read operations
  • Retrieve data in a single database operation
  • "dot" notation

Untitled Slide

Referencing

  • Many:Many relationship
  • Frequently read with rarely accessed sub-doc
  • Documents related to many others collection
  • embedding would result in duplication of data without read performance

Untitled Slide

Indexes

  • Default: _id
  • Single Field
  • Compound Index
  • Multikey Index
Photo by koalazymonkey

Index Properties

  • Unique
  • Spare
  • Partial
  • TTL
Photo by koalazymonkey

Covered Queries

Transactions

  • Atomic Operations
  • Possible approaches: - Restructure - Provide transactions on application level - Tolerate
Photo by TonZ

Transactions

  • $isolated
  • Two-phase commit
Photo by TonZ

MongoDB limits

  • 16MB per document
  • No multi-row transactions
  • No foreign keys
  • Text and Geospatial indexes can't be use at once

MongoDB pros

  • Changeable list of entity properties
  • Scalability
  • Object-oriented API
  • High performance (up to 1000's millions queries/sec)
Photo by owenwbrown

MongoDB cons

  • Memory usage
  • No Joins
  • Possible data loss
  • Lack of SQL support

Consider MongoDB

  • Scaling on demand
  • Flexible schama
  • Geo spatial queries
  • Real-time analytics
Photo by falequin

Forget about MongoDB when

  • You will use a lot text indexing
  • Multi-row transactions are needed
  • Nanoseconds latency writing is needed (real time tick data)
  • You want to do a batch processing
  • Joins across collections is needed

Q & A

@WSztajerowski