Latinoware
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,539
On Slideshare
1,538
From Embeds
1
Number of Embeds
1

Actions

Shares
Downloads
18
Comments
0
Likes
1

Embeds 1

http://www.slideshare.net 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. base de dados orientada a documentos para aplicações Web Kristina Chodorow
  • 2. Who am I? Software Engineer at Here from New York City
  • 3. Why Use Non-Relational DBs?
  • 4. CAP • Consistency nome : "joe" nome : "joe" • Availability • Partitioning
  • 5. Key-Value Stores Key Value foo bar x 123 ts 6:13:26 12/3/1945 data x9Fx44x1e Tokyo Cabinet, Dynamo, MemcacheDB
  • 6. Key-Value Stores •Fast •Too simple •Simple
  • 7. Column-Oriented Cassandra
  • 8. Document-Oriented { date : Date(2007-05-07), time : { start : 9.25, end : 10.25 } sum : 0, comments : ["task 1", "run 4", "testing module"] } vs.
  • 9. Consistency Availability Partitioning
  • 10. Consistency Availability master Partitioning slave
  • 11. Consistency Availability Partitioning slave
  • 12. Consistency Availability Partitioning master
  • 13. Consistency Availability slave Partitioning master
  • 14. Consistency Availability Partitioning Pair Router Pair Pair ...eventual consistency
  • 15. Introduction to MongoDB
  • 16. A JavaScript Database $ mongodb-linux-1.0/bin/mongo MongoDB shell version: 1.0.0 url: test connecting to: test type "help" for help >
  • 17. JSON and BSON Strict JSON types: { x : null, y : true, z : 123, w : "xyz", a : { b : 1 }, c : [1, 2, 3] } Mongo JSON adds: { ts : new Date(), query : /regex/ig, _id : new ObjectId() }
  • 18. Collections, not Tables
  • 19. Collections { date : Date(2007-05-07), time : { start : 9.25, end : 10.25 } sum : 0, comments : ["task 1", "run 4"] }
  • 20. Using the Shell > db test > use xyz > db xyz > db.splorch.find() >
  • 21. Inserting > db.foo.insert({name : "Joe", age : 34}) > db.foo.find({name : "Joe"}) { "_id" : ObjectId("2fe3e4d892aa73234c910bed"), "name" : "Joe", "age" : 34 }
  • 22. Object Ids an autogenerated primary key "_id" : ObjectId("2fe3e4d892aa73234c910bed") 12 bytes: 2fe3e4d892aa73234c910bed |------||----||--||----| ts mac pid inc
  • 23. Nested Objects > db.blog.insert({title : "First Post", content : "Hello, world!", author : {name : "Joe", id : 123}, comments : [] })
  • 24. Querying posts = db.blog.find({ "author" : "Joe"}) commentsByFred = db.blog.find({ "comments.author" : "Fred"}) commentedByFred = db.blog.find({ "comments.author" : /fred/i})
  • 25. Speaking of indexing… db.people.ensureIndex({"age" : 1}); db.people.ensureIndex({ "name" : -1, "ts" : -1, "comments.author" : 1 });
  • 26. Updating db.blog.update({title : "First Post"}, { $push : { comments : { author : "Fred", comment : "Dumb post." } } });
  • 27. …which gives us: > db.blog.findOne() { _id : ObjectId("4ae06192213900000000745c"), "title" : "First Post", "content" : "Hello, world!" "author" : {"name" : "Joe", "id" : 123} "comments" : [{ "author" : "Fred", "comment" : "Dumb post" }] }
  • 28. $ instead of >, <, =, etc. $gt, $gte, $lt, $lte, $eq, $neq, $exists, $set, $mod, $where, $in, $nin, $inc $push, $pull, $pop, $pushAll, $popAll db.foo.bar.find({x : {$gt : 4}})
  • 29. $where db.blog.findOne({$where : 'this.y == (this.x + this.z)'}); Will work: {"x" : 1, "y" : 4, "z" : 3} {"x" : "hi", "y" : "hibye", "z" : "bye"} Won’t work: {"x" : 1, "y" : 1}
  • 30. Optimizing $where db.blogs.findOne({ name : "Sally", age : {'$gt' : 18}, $where : 'Array.sort(this.interests)[2] == "volleyball"'});
  • 31. Cursors cursor = db.blah.find(array("foo" : "bar")) while (cursor.hasNext()) { obj = cursor.next() }
  • 32. Applications
  • 33. soliMAP @trackmeet FetLife Dextify2
  • 34. Paging cursor = db.results.find() .sort({"ts" : -1}) .skip(page_num * results_per_page) .limit(results_per_page);
  • 35. Logging • insert/update/remove is fast • Capped collections • Schemaless • $inc for counts
  • 36. Storing Files Max: 4Mb
  • 37. Storing Files (More than 4 Mb)
  • 38. Storing Files J J J chunks J J J J J J _id : J files
  • 39. Storing Files ObjectId fileId = new ObjectId(); fileObj = { _id : fileId, filename : "ggbridge.png", user : "joe", takenIn : "San Francisco" } chunkObj = { fileId : fileId, chunkNum : N data : <binary data> }
  • 40. Aggregation group =~ GROUP BY Map/Reduce db.runCommand({ mapreduce : <collection>, map : <mapfunction>, reduce : <reducefunction> [, query : <query filter object>] [, out : <outputcollectionname>] [, keeptemp: <true|false>] [, finalize : <finalizefunction>] })
  • 41. www.mongodb.org
  • 42. Drivers C#, Erlang, Factor
  • 43. Thank you! kristina@10gen.com @kchodorow @mongodb irc.freenode.net#mongodb www.mongodb.org