Devoxx11: Building Web Applications with MongoDB

Brendan McAdams

mongoDB is a nosql DB, ie. a "non-relational" DB

  • no joins
  • no referential integrity
  • no complex transactions --> not suitable for higly transactional apps
  • but: focus on horizontal scalability
    • sharding
    • replica's
  • a scheme-less DB
    • unique ObjectID is automatically generated (based on time, machine, pid & counter)
    • flexible structures: adding/omitting elements is easy
  • native JSON support
    • hierarchical 'documents'
    • arrays
    • internally, an optimized format is used: BSON:http://bsonspec.org
  • support for indexes (+ 'multi-indexes' on arrays)

technical specifics:

  • based on memory mapped files:
    • OS maps the files in the RAM.
    • pagefaults are expensive --> keep working set in RAM
      • provide sufficient RAM
      • prewarm the DB
    • only use 64bit OS & binaries
  • Intel-only (little endian)
  • filesystem
    • Ext4 & Xfs: only filesystems with support for posix_fallocate()
    • set noatime, noadirtime in /etc/fstab
  • 'documents' (i.e. objects) have a max. size of 16mb
  • accessible over tcp/ip: Mongo Wire Protocol
  • UTF-8
  • the data is stored in fysical files / 'extents'

modeling for mongoDB:

  • think of 'documents' instead of 'rows'
  • favor embedding over referencing -- mongoDB offers no referential integrity (aka foreign keys)
  • think of the access patterns of your data

other specifics:

  • support for MapReduce
  • geospatial indexing
  • indexes (internally btrees)
  • query optimization
  • advanced queries ($lt, $all, $in...)
  • gridfs:
    • large 'chunked' files
    • distributed (sharded)
    • accessible through a regular java.io.File

No comments: