Your SlideShare is downloading. ×
A Year With MongoDB: The Tips
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

A Year With MongoDB: The Tips

1,033
views

Published on

Tips for every mongodb user, the tips itself is coming from self experience after 1 (more) year using MongoDB as main database

Tips for every mongodb user, the tips itself is coming from self experience after 1 (more) year using MongoDB as main database


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,033
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
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

Transcript

  • 1. #AYearWithMongoDB The Tips By: @rizkyabdilahEmail: rizky@abdi.la / rizky@mindtalk.com
  • 2. What is MongoDB?Document databaseSchema-freeMemory mappedOk, the tips..
  • 3. #1. Avoid RegExpExample case, Mindtalk username:Valid regex ([a-zA-Z0-9_.]+)
  • 4. No!db.user.ensureIndex({name: 1})db.user.insert({name: “Danny”})db.user.find({name: /dAnny/i})
  • 5. Yesdb.user.ensureIndex({lower_name: 1})db.user.insert({name: “Danny”, lower_name: “danny”})db.user.find({lower_name: “dAnny”.toLowerCase()})
  • 6. ComparissonIndex not used when query using RegExp
  • 7. #2. Tokenize field nameBecause of schema-free, every document have a own schema (field-name or key in json)
  • 8. #2. Tokenize field nameBecause of schema-free, every document have a own schema (field-name or key in json)All of your key-name go into your valuable RAM
  • 9. #2. Tokenize field nameBecause of schema-free, every document have a own schema (field-name or key in json)All of your key-name go into your valuable RAMImagine if youve very-very long key- name, and it repeated in every document. No need to explain
  • 10. Example Case: Ndayak Stream
  • 11. How we tackle thisOriginal Now: Implementation: Index size ~ 12GB> 136 million doc Space size ~ 15GBIndex size > 60GB AvgObjSize 112Space size > 24GB bytesAvgObjSize 210
  • 12. #3. Use single compound-key index Instead of many single-key index
  • 13. Nodb.post.ensureIndex({user_id: 1, timepos: -1})db.post.ensureIndex({channel_id: 1, timepos: -1})Query finddb.post.find({user_id: “uid”}).sort({timepos: -1})db.post.find({channel_id: “ch_id”}).sort({timepos: -1})
  • 14. Yesdb.post.ensureIndex({user_id:1, channel_id: 1, timepos: -1})Query find, it will use the same indexdb.post.find({user_id: “uid”}).sort({timepos:-1})db.post.find({channel_id: “chid”}).sort({timepos:-1})
  • 15. Later DiscussionsGlobal write lock (introducing yield on MongoDB 2.0)Normalize own schemaSharding?
  • 16. Thank You Ps: dont forget to join channel#EngineerBlog if you interested in advance :)