Slide 1

Slide 1 text

An introduction to MongoDB Russell Smith Friday, 20 April 12

Slide 2

Slide 2 text

/usr/bin/whoami • Russell Smith • Consultant for UKD1 Limited, • External consultant for 10gen • Help with code, architecture, infrastructure, devops, sysops, capacity planning, etc • <3 MongoDB, MySQL, Redis, Gearman, Neo4j, Kohana, Riak, PHP, Debian, AWS, etc Friday, 20 April 12

Slide 3

Slide 3 text

What is MongoDB • A scalable, high-performance, open source, document-oriented database. • Stores JSON like documents • Commercially backed by 10gen Friday, 20 April 12

Slide 4

Slide 4 text

Why choose it? • Schema-less • Simple • Reliable • Scalable • Drivers Friday, 20 April 12

Slide 5

Slide 5 text

Who uses it? • Foursquare • Disney • Craigslist • MTV Networks • O2 • Telefonica Friday, 20 April 12

Slide 6

Slide 6 text

Basics • insert • find • update • remove • ensureIndex Friday, 20 April 12

Slide 7

Slide 7 text

Insert • db.test.insert({hello: ‘world’}); Friday, 20 April 12

Slide 8

Slide 8 text

Find • db.test.find() • Equivalent of SELECT * FROM test; > db.test.insert({hello: ‘world’}); > db.test.find(); { "_id" : ObjectId("4e7c9f464bdd7534bc498ff7"), "hello" : "world" } Friday, 20 April 12

Slide 9

Slide 9 text

Updating • db.test.update(, ) > db.test.find(); { "_id" : ObjectId("4e7c9f464bdd7534bc498ff7"), "hello" : "world" } > db.test.update({hello:‘world’}, {hello: ‘seedhack’}); > db.test.find(); { "_id" : ObjectId("4e7c9f464bdd7534bc498ff7"), "hello" : "seedhack" } Friday, 20 April 12

Slide 10

Slide 10 text

Removing • db.test.remove() > db.test.find(); { "_id" : ObjectId("4e7c9f464bdd7534bc498ff7"), "hello" : "seedhack" } > db.test.remove({hello: ‘seedhack’}); > db.test.count() 0 > Friday, 20 April 12

Slide 11

Slide 11 text

Indexes • It’s usually a good idea to index your collections • How and which columns depends on what you are doing • explain > db.test.ensureIndex({hello:1}) Friday, 20 April 12

Slide 12

Slide 12 text

More advanced • sort, count, limit, special operators • Capped collections • Geospatial indexing • MapReduce • Replica sets • Sharding Friday, 20 April 12

Slide 13

Slide 13 text

Getting started... • Download & install - http://www.mongodb.org/downloads • Online shell - http://www.mongodb.org/ Friday, 20 April 12

Slide 14

Slide 14 text

Questions / Further • Come and ask me questions • Updates can also push, set, increment, decrement, etc http://bit.ly/gEfKOr • Indexes can be across multiple keys, 2D (geo) and ASC / DESC http://bit.ly/hpK68Q • SQL -> Mongo chart http://bit.ly/ig1Yfj Friday, 20 April 12