Upload
lee-theobald
View
523
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
AN INTRODUCTION TO
But First, A Little About Me My name’s Lee Theobald. Hello! Twitter: @Leesy Never updated blog:
http://www.ltheobald.co.uk/ I’m a developer at a small search
company in Cambridge called Open Objects.
SO WHAT IS MONGODB?
NoSQL database The name is short for humongous Open source with development lead
by 10Gen (http://www.10gen.com) Document Based Schema-less Highly Scalable MapReduce Replication & Auto Sharding
Document Store Data is stored in the form of JSON data.
{ "_id" : ObjectId("4ccbfc75bd163019417c27f8"), "title": “Hello World! ", "author": { "firstname": "Joe", "lastname": "Bloggs" }, "tags": ["test", "foo", "bar"] }
Familiar Structure
MongoDB instances contain a number of databases which in turn contain a number of collections.
Think of MySQL with it’s databases & tables.
But collections can also be nested. E.g.customer_a (Database)○ logs_201009 (Collection)
top_queries(Collection)
Inserts – Easy As Pie!
use cookbook;db.desserts.save({ name: "Cherry Pie", ingredients: ["cherries", "pie"], cooking_time: 30});
Searching – A Piece Of Cake
db.recipes.find({ cooking_time: { “$gte”: 10, “$lt”: 30}})
db.recipes.findOne()
Some More Advanced Query Syntax Limiting
db.find().limit(10); Skipping
db.find( ).skip(5); Sorting
db.find({…}).sort({cooking_time: “-1”}); Cursors
var cur = db.find({…}).cursor()cur.forEach( function(x)
{ print(tojson(x)) });
MapReduce
Great way of doing bulk manipulation or aggregation.
2 or 3 functions written in JavaScript that execute on the server.
An example use could be generating a list of top queries from some search logs.
Map Function Takes some input of the form of key/value
pairs. Does something with that Returns 0 or more key/value pairs
map = function() { if (!this.query) { return; } emit (this.query, {count: 1});}
Reduce Function Takes the results from the map function Does something (normally combine the results) Produces output in key/value pairs
reduce = function(key, values) { var count = 0; values.forEach(function(v) { count += v[‘count’]; } return {count: count;}}
Replica Sets
Master/Slave configuration If your primary server goes down,
one of the secondary ones takes over.
Auto Sharding
But Why Not Try It Yourself Download it at:
http://www.mongodb.org Online tutorial at:http
://www.mongodb.org/display/DOCS/Tutorial
Some handy MongoDB sites:MongoDB Cookbook:
http://cookbook.mongodb.org/Kyle Banker’s blog:
http://kylebanker.com/blog/
Thanks For Listening.Any (easy) Questions?