Your SlideShare is downloading. ×
0
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
MongoDB at GUL
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

MongoDB at GUL

410

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
410
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

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
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. MongoDBor: How I Learned to Stop Worrying and Love the JSON
    • 2. • Humongous: Slang. Extraordinary large; expressive coinage, perhaps reflecting huge and monstrous, with stress pattern of tremendous• Open source NoSQL database • Written in C++ • https://github.com/mongodb/mongo
    • 3. ProductionDeployments
    • 4. Format• BSON: Binary encoded serialization of JSON documents• Characteristics • Lightweight: minimum overhead • Traversable • Efficient: encoding and decoding
    • 5. JSON{ _id : Object(), name : “mongoDB”, date : Date(), presenter: “isra”, attendants : [ {name:”ana”, age:23}, {name:”luis”, age: 32} ]}
    • 6. Data schema• Database Database Collection• Collection Document• Documents (JSON) { user: 1, name: [] }
    • 7. Collection• Flexible: no fixed structure • ALTER TABLE (implicit)• Created in the first insertion
    • 8. Document• JSON document • _id • Object composed of fields • Arrays • Special objects: id, date, etc.
    • 9. SQL to Mongo mapping
    • 10. MongoDB basics• Default port: 27017• Optional authentication• Data location: /data/db/• Modes: automatic replication, automatic fail- over
    • 11. Drivers• Officially supported • C, C++, Erlang, Haskell, Java, Javascript, .NET, Perl, PHP, Python, Ruby, Scala• Community supported • ActionScript, C#, Delphi, etc.
    • 12. Connection• mongodb://username:password@host:port/ database?options • username and password are optional • port: 27017 by default • database: admin database by default • options: name=value pairs
    • 13. Basics• show dbs• use db_name• show collections (current db)• show users (current db)
    • 14. InsertionColección de las charlas del GUL:db.gul.insert ({ name : “mongoDB”, date : new Date(), presenter: “isra”, attendants : [ {name:”ana”, age:23}, {name:”luis”, age: 32} ]})
    • 15. Querying• Charla de MongoDB: db.gul.find({name:”mongoDB”});• Charlas a las que asistió ana: db.gul.find({attendants.name:”ana”});• Nombre de las charlas impartidas por isra: db.gul.find({presenter:”isra”}, {name:1});
    • 16. Querying II• Charlas ordenadas por nombre: db.gul.find().sort({name:1});• Las 5 primeras charlas: db.gul.find().limit(5);• Las 5 siguientes: db.gul.find().skip(5).limit(5);• La primera charla: db.gul.findOne()
    • 17. Querying III• Charlas con algún asistente menor de edad: db.gul.find({attendants.age:{$lt: 18}});• Las charlas anteriores entre el lunes y jueves: db.gul.find({date: {$gt:new Date(2012,02,11), $lt:new Date(2012,02,14)} });
    • 18. Querying IV• Charlas asistidas por pedro y/o ana: db.gul.find({“attendants.name”: {$in:[“pedro”, “ana”]} });• Charlas asistidas por 10 personas: db.gul.find({attendants:{$size:10}});
    • 19. Querying V (group)• Número de charlas: db.gul.count();• Número de charlas impartidas por isra: db.gul.count({presenter:”isra”});• Distintos asistentes a todas las charlas: db.gul.distinct(“attendants.name”);
    • 20. Querying VI (group)• Número de charlas con los mismos asistentes db.gul.group({ key: {attendants:1}, initial: {sum:0}, reduce: function(doc,prev){ prev.sum+=1; } });
    • 21. Querying VII (group)• Número de charlas con los mismos asistentes, desde el martes db.gul.group({ key: {attendants:1}, initial: {sum:0}, reduce: function(doc,prev){ prev.sum+=1;}, cond: {date: {“$gte”:new Date(2012, 2,12)}} });
    • 22. Querying VIII (group)• Número de charlas con los mismos asistentes, y media de edades db.gul.group({ ... finalize: function(doc){ var sum=0; for(var i in doc.attendants){ sum+=doc.attendants[i].age;} doc.av_age=sum/ doc.attendants.length; } });
    • 23. Querying IX (group)• Número de charlas por día de la semana db.gul.group({ ... keyf: function(doc){ return {week_day: doc.date.getDay()}; } });
    • 24. Update• db.gul.save(x) //updates if exits; inserts if new• Actualizar ponentes de la charla de Crafty db.gul.update({name:”Crafty”}, {$set: {presenter:[“javi”,“isra”]}});• Nuevo asistente a la charla db.gul.update({name:”mongoDB”},{$push: {name:”pepe”, age:19}});
    • 25. Update II• findAndModify
    • 26. Remove• db.gul.remove() //removes all• db.gul.remove({presenter:”isra”})
    • 27. Database references• Simple direct linking isra = db.gul_members.findOne() {_id: ObjectId(“ad234fea23482348”), name:”isra”, age:31, languages:”js”} db.gul.find({“attendants.name”:isra._id})
    • 28. Database references• DBRef isra = db.gul_members.findOne() {_id: ObjectId(“ad234fea23482348”), name:”isra”, age:31, languages:”js”} db.gul.insert({name: “mongoDB”, presenter:new DBRef(“gul_members”,isra._id ))
    • 29. Map/Reduce• Batch processing of data and aggregation operations• Where GROUP BY was used in SQL• Input from a collection and output going to a collection
    • 30. Map/reduce (II)• Número de cursos asistidos por persona var map = function(){ for(var i in this.attendants){ emit(this.attendants[i].name,1); } }
    • 31. Map/reduce (III)• Número de cursos asistidos por persona var reduce = function(key, values){ var sum=0; for (var i in values){ sum+=values[i]; } return sum; }
    • 32. Map/reduce (IV)• Número de cursos asistidos por persona db.gul.mapReduce({ map: map, reduce: reduce, {out: “my_new_collection”} });
    • 33. Schema Design• Function of the data and the use case• Decisions • # of collections • Embedding or linking • Indexes • Sharding
    • 34. Indexes• Data structure• Query optimization• B-Tree indexes• db.gul.ensureIndex({ name:1 });
    • 35. Sharding• Scalability• Horizontal partitioning of a database• A BSON document stored in ONE shard• Shard key• Mongo offers auto-sharding
    • 36. Sharding• MongoDB offers sharding • Auto balancing • Easy addition of new machines • Up to 1k nodes • No single point of failure • Automatic failover
    • 37. References• MongoDB devel docs: http:// www.mongodb.org/display/DOCS/ Developer+Zone• MongoDB FAQ: http://www.mongodb.org/ display/DOCS/Developer+FAQ• MongoDB cookbook: http:// cookbook.mongodb.org/
    • 38. References• Kyle Banker’s blog: • Aggregation: http://kylebanker.com/blog/ 2009/11/mongodb-count-group/ • e-Commerce example: http:// kylebanker.com/blog/2010/04/30/ mongodb-and-ecommerce/
    • 39. Thank you very much! Any questions?

    ×