When?, Why? and What? of MongoDB

3,997 views
3,910 views

Published on

I've been using mongodb for 2 years and many times I've faced myself asking "why should I use it for this?" or "when should I really use Mongodb?" and many other times "What did I do wrong?".

Experiences, examples and real use cases many times say things that benchmarks or technical documentation don't, that for, I'll be presenting the When, Why and What of mongodb. For real, that's what really matters.

1 Comment
13 Likes
Statistics
Notes
No Downloads
Views
Total views
3,997
On SlideShare
0
From Embeds
0
Number of Embeds
808
Actions
Shares
0
Downloads
55
Comments
1
Likes
13
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • When?, Why? and What? of MongoDB

    1. 1. When? Why?What? Flavio [FlaPer87] Percoco Premoli flaper87@flaper87.org twitter: @flaper87
    2. 2. When?
    3. 3. Dictionaries! When?
    4. 4. Spidering!Dictionaries! When?
    5. 5. Statistics! Spidering!Dictionaries! When?
    6. 6. Queues! Statistics! Spidering!Dictionaries! When?
    7. 7. Loggin g! Queues! Statistics! Spidering!Dictionaries! When?
    8. 8. Why?
    9. 9. * Unstructured Data! (Spidering) Why?
    10. 10. * Lot of reads! (Dictionaries, Queues)* Unstructured Data! (Spidering) Why?
    11. 11. * [JB]son like Document Oriented API (All) * Lot of reads! (Dictionaries, Queues) * Unstructured Data! (Spidering) Why?
    12. 12. * Lot of writes! (Logging, Statistics, Queues)* [JB]son like Document Oriented API (All) * Lot of reads! (Dictionaries, Queues) * Unstructured Data! (Spidering) Why?
    13. 13. * Make sure you create the right indexes# lets get our collectioncollection = connection[dictionaries][it]def insert_word(word, data): collection.update({word : word}, data, upsert=True) What?
    14. 14. * Make sure you create the right indexes# lets get our collectioncollection = connection[dictionaries][it]# lets ensure there’s an index for the key wordcollection.ensure_index([("word", pymongo. ASCENDING)])def insert_word(word, data): collection.update({word : word}, data, upsert=True) What?
    15. 15. * Make sure you save what you really needdef parse(response): url_netloc = urlparse.urlsplit(response.url).netloc crawled = { "url" : response.url, "base_url" : url_netloc, "content" : response.body_as_unicode(), "status" : response.status, "encoding" : response.encoding, "headers" : response.headers, "lastcrawl" : time.time(), } collection.update({url : response.url}, crawled, True) What?
    16. 16. * Make sure you understand that schemaless != messlogs = [ {url : "http://www.google.com", "time" : 1304336526.011287}, {address : "http://www.yahoo.com", "time" : 1304336551.0424709 }]def insert_log() for log in logs: collection.insert(log) What?
    17. 17. * Make sure you understand that schemaless != messlogs = [ {url : "http://www.google.com", "time" : 1304336526.011287}, {address : "http://www.yahoo.com", "time" : 1304336551.0424709 }]def insert_log() for log in logs: log_to_insert = { "url" : log.get(url, log.get(address)), "time" : log.get(time) } collection.insert(log_to_insert) What?
    18. 18. * “Relate” what you occasionally need, “Embed” what you always need message = { msg : "This is a test message", time : time.time(), user : { username : flaper87, email : flaper87@flaper87.org, } } What?
    19. 19. * ObjectIDs have an embedded datetimedef _get(self, queue): try: msg = self.client.database.command("findandmodify", "messages", query={"queue": queue}, sort={"_id": pymongo.ASCENDING}, remove=True) except errors.OperationFailure, exc: if "No matching object found" in exc.args[0]: raise Empty() raise return deserialize(msg["value"]["payload"]) What?
    20. 20. Lets talk about mongoDB!! Thanks!!
    21. 21. Thanks!!Lets talk about mongoDB!! Thanks 10gen!!

    ×