Bar Camp Auckland - Mongo DB Presentation BCA4

20
SELECT wages FROM companies WHERE coders = “sucker” NO, NO SQL Wednesday, 21 July 2010

description

Bar Camp Auckland Slides on Mongo DB

Transcript of Bar Camp Auckland - Mongo DB Presentation BCA4

Page 1: Bar Camp Auckland - Mongo DB Presentation BCA4

SELECT wages FROM companies WHERE coders = “sucker”

NO, NO SQL

Wednesday, 21 July 2010

Page 2: Bar Camp Auckland - Mongo DB Presentation BCA4

Noise

Wednesday, 21 July 2010

Page 3: Bar Camp Auckland - Mongo DB Presentation BCA4

Lots of pretty pictures to fool you.

Wednesday, 21 July 2010

Page 4: Bar Camp Auckland - Mongo DB Presentation BCA4

It is a rich document store.

Its Not Relational - Get Over It.

schemas for mongo : http://www.kurl.ws/wJ

Its a change

Wednesday, 21 July 2010

Page 5: Bar Camp Auckland - Mongo DB Presentation BCA4

schemas for mongo : http://www.kurl.ws/wJ

• Document-oriented storage » JSON-style documents with dynamic schemas offer simplicity and power.• Full Index Support » Index on any attribute, just like you're used to.• Replication & High Availability »Mirror across LANs and WANs for scale and peace of mind.• Auto-Sharding » Scale horizontally without compromising functionality.• Querying » Rich, document-based queries.• Fast In-Place Updates »Atomic modifiers for contention-free performance.• Map/Reduce » Flexible aggregation and data processing.• GridFS » Store files of any size without complicating your stack.• Commercial Support »Commercial support, training, and consulting available.

MongoDB bridges the gap between key-value stores (which are fast and highly scalable) and traditional RDBMS systems (which provide rich queries and deep functionality).

MongoDB (from "humongous") is a scalable, high-performance, open source, document-oriented database. Written in C++, MongoDB features:

What

Wednesday, 21 July 2010

Page 6: Bar Camp Auckland - Mongo DB Presentation BCA4

more info: www.mongodb.org

mongodb.org Supported• C• C++• Java• Javascript• Perl• PHP• Python• Ruby

Community Supported• REST• C# and .NET• Clojure• ColdFusion• Delphi• Erlang• Factor• Fantom• F#• Go• Groovy• Haskell• Javascript

• Lua• node.js• Objective C• PHP• PowerShell• Python• Ruby• Scala• Scheme (PLT)• Smalltalk

Supported Drivers

Wednesday, 21 July 2010

Page 7: Bar Camp Auckland - Mongo DB Presentation BCA4

Install on ubuntu

All Instructions http://kurl.ws/wH

EDIT YOUR SOURCES FILEnano /etc/apt/sources.list

ADD THE FOLLOWING LINEdeb http://downloads.mongodb.org/distros/ubuntu 9.4 10gen

NOW UPDATE APTapt-get update

apt-get install mongodb-stable

apt-get install php5-dev

INSTALL THE PHP DRIVERpecl install mongo

Wednesday, 21 July 2010

Page 8: Bar Camp Auckland - Mongo DB Presentation BCA4

Install on ubuntu view db stats : http://localhost:28017/

Wednesday, 21 July 2010

Page 9: Bar Camp Auckland - Mongo DB Presentation BCA4

Durability

Long long story

Durability - You had to ask

Wednesday, 21 July 2010

Page 10: Bar Camp Auckland - Mongo DB Presentation BCA4

Examples - from the console

Wednesday, 21 July 2010

Page 11: Bar Camp Auckland - Mongo DB Presentation BCA4

Examples - from the console

> db.accounts.count() 1> db.accounts.find().forEach(function(doc){ print(tojson(doc));});

Wednesday, 21 July 2010

Page 12: Bar Camp Auckland - Mongo DB Presentation BCA4

Examples - from the console

> db.colors.find({name:'green'}) { "_id" : ObjectId("4bed7af40b4acd070c593ba7"), "name" : "green", "primary" : true }

> use testing switched to db testing> db.colors.insert({name:'red', primary:true})> db.colors.insert({name:'green', primary:true})> db.colors.insert({name:'blue', primary:true})> db.colors.insert({name:'purple', primary:false})> db.colors.insert({name:'orange', primary:false})> db.colors.insert({name:'yellow', primary:false})

SELECT * from colors WHERE name = 'green' ; because I am sucker.

Wednesday, 21 July 2010

Page 13: Bar Camp Auckland - Mongo DB Presentation BCA4

Examples - from the console

db.people.update( { name:"Joe" }, { $inc: { x:1, y:1 } }, true );Upsert

db.users.find().skip(20).limit(10);Skip and Limit

db.users.find({last_name: 'Smith'}, {'ssn': 1});Limiting Fields, only get ssn

db.collection.find({ "field" : { $gt: value } } );Greater than

db.postings.find( { "author.name" : "joe" } );Values in Embeded Objects

db.myCollection.find().sort( { ts : -1 } ); // sort by ts, descending orderSort

Wednesday, 21 July 2010

Page 14: Bar Camp Auckland - Mongo DB Presentation BCA4

Examples - Real PHP

Wednesday, 21 July 2010

Page 15: Bar Camp Auckland - Mongo DB Presentation BCA4

Examples - Real PHP

Wednesday, 21 July 2010

Page 16: Bar Camp Auckland - Mongo DB Presentation BCA4

OLD

Wednesday, 21 July 2010

Page 17: Bar Camp Auckland - Mongo DB Presentation BCA4

OLD

Wednesday, 21 July 2010

Page 18: Bar Camp Auckland - Mongo DB Presentation BCA4

Mongo Hub GUI

Wednesday, 21 July 2010

Page 19: Bar Camp Auckland - Mongo DB Presentation BCA4

backup

-fsync (mongo command) - shutdown copy /data/db

- mongodump

Wednesday, 21 July 2010

Page 20: Bar Camp Auckland - Mongo DB Presentation BCA4

or

Facebook still uses MySQL, a lot. Wikipedia uses MySQL, a lot. FriendFeed uses MySQL, a lot. NoSQL is a great tool, but it’s certainly not going to be your competitive edge, it’s not going to make your app hot, and most of all, your users won’t give a shit about any of this.

What am I going to build my next app on? Probably Postgres. Will I use NoSQL? Maybe. I might also use Hadoop and Hive. I might keep everything in flat files. Maybe I’ll start hacking on Maglev. I’ll use whatever is best for the job. If I need reporting, I won’t be using any NoSQL. If I need caching, I’ll probably use Tokyo Tyrant. If I need ACIDity, I won’t use NoSQL. If I need a ton of counters, I’ll use Redis. If I need transactions, I’ll use Postgres. If I have a ton of a single type of documents, I’ll probably use Mongo. If I need to write 1 billion objects a day, I’d probably use Voldemort. If I need full text search, I’d probably use Solr. If I need full text search of volatile data, I’d probably use Sphinx.

Wednesday, 21 July 2010