MongoDB 101

MongoDB 101

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

C7f3b4756d808ef0e2548bd0965ac225?s=128

Nick Jackson

May 07, 2012
Tweet

Transcript

  1. 2.

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

    University of Lincoln • @jacksonj04
  2. 4.

    Eh?

  3. 5.

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

    doesn’t have schemas. • (Generally) works at web-scale. • (Generally) doesn’t do relational integrity.
  4. 6.
  5. 8.

    Ye Olde SQL id name email office building 1 Nick

    ... 3107 MHT 2 Joss ... 3015 MHT 3 Harry ... NULL MHT
  6. 9.

    :-(

  7. 12.

    Documents: Awesome! { name: ‘Joss’, email: ‘jwinn@lincoln.ac.uk’, location: { office:

    ‘3105’, building: ‘MHT’ }, likes: { music: [‘Folk’, ‘Hip-Hop’], drink: [‘Coffee’, ‘Ale’] } }
  8. 19.

    Query Be Simple... > db.people.find() { "_id" : ObjectId("4fa...103"), "name"

    : "Nick" } { "_id" : ObjectId("4fa...104"), "name" : "Joss" } { "_id" : ObjectId("4fa...105"), "name" : "Harry" }
  9. 23.

    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" ] }
  10. 24.

    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" }
  11. 25.

    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.
  12. 27.

    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.
  13. 28.

    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.
  14. 29.

    Some MongoDB Users • Craigslist • MTV • SourceForge •

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