Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MongoDB 101

MongoDB 101

A crash course on MongoDB I gave to attendees at the JISC MRD Hackday organised by DevCSI.

Nick Jackson

May 07, 2012
Tweet

More Decks by Nick Jackson

Other Decks in Technology

Transcript

  1. I am... • Nick Jackson • Awesome Developer Dude •

    University of Lincoln • @jacksonj04
  2. Eh?

  3. NoSQL • Is not a specification (unlike SQL). • (Generally)

    doesn’t have schemas. • (Generally) works at web-scale. • (Generally) doesn’t do relational integrity.
  4. Ye Olde SQL id name email office building 1 Nick

    ... 3107 MHT 2 Joss ... 3015 MHT 3 Harry ... NULL MHT
  5. :-(

  6. Documents: Awesome! { name: ‘Joss’, email: ‘[email protected]’, location: { office:

    ‘3105’, building: ‘MHT’ }, likes: { music: [‘Folk’, ‘Hip-Hop’], drink: [‘Coffee’, ‘Ale’] } }
  7. Query Be Simple... > db.people.find() { "_id" : ObjectId("4fa...103"), "name"

    : "Nick" } { "_id" : ObjectId("4fa...104"), "name" : "Joss" } { "_id" : ObjectId("4fa...105"), "name" : "Harry" }
  8. Queries are powerful > db.people.update({name:'Joss'},{name:'Joss',likes: ['coffee','folk music']}) > db.people.find({likes:'coffee'}) {

    "_id" : ObjectId("4fa...103"), "name" : "Nick", "likes" : [ "coffee" ] } { "_id" : ObjectId("4fa...104"), "name" : "Joss", "likes" : [ "coffee", "folk music" ] }
  9. Deletes are also easy > db.people.remove({name:'Nick'}) > db.people.find() { "_id"

    : ObjectId("4fa...104"), "name" : "Joss", "likes" : [ "coffee", "folk music" ] } { "_id" : ObjectId("4fa...105"), "name" : "Harry" }
  10. Cool Things! • Geospatial indexes. db.places.find({loc:{$near:[-2, 53]}}) • JavaScript in

    the Mongo shell. • Map/Reduce operations. • Can be used as a filesystem.
  11. It’s not ACID • Set of atomic operators, but no

    things like transactions. • No enforced consistency. At all. • No locking, so updates can collide and be lost. • Disk writes are (usually) deferred, so data can be lost in failures.
  12. It’s not ‘Enterprise’ • Your DBAs will find it new

    and scary. • You need to un-learn a lot of the SQL mindset. • It’s not seen as ‘proven’, but this is generally rubbish.
  13. Some MongoDB Users • Craigslist • MTV • SourceForge •

    Disney • National Archives • HM Government • The Guardian • New York Times • bit.ly • GitHub • Foursquare • http://lncn.eu/fhx5