Collection “product”:        Collection “order”:{                            {     "_id" : productId1,         "_id" : ord...
Collection “product”:            Collection “order”:{                                {    "_id" : productId1,             ...
Collection “order”:{    "_id" : orderId,    "user" : userInfo,    "items" : [          {              "_id" : productId1, ...
Collection “order”:{                                                     order    "_id" : orderId,    "user" : userInfo,  ...
Collection “order”:                 Collection “performance_rating”:{                                   {    "_id" : order...
Collection “order”:                  Collection “performance_rating”:{                                    {    "_id" : ord...
Collection “blog”:{                                  comment    "_id" : blogId,    "user" : userInfo,    "tags" : [tag1, t...
Collection “comment”:Collection “blog”:                   {{                                         "_id" : commentId,   ...
> db.coll.stats(){   ...    #1    "paddingFactor" : 1.4099999999940787,    ...}
Collection “access_history”:{    "_id" : pageId,                          “start”          6    "start" : time,           ...
Collection “access_history”:{    "_id" : pageId,    "start" : time,    "visits" : {         "minutes" : [            [0,0,...
Collection “access_history”:{    "_id" : pageId,                               $inc    "start" : time,    "visits" : {    ...
> collection.insert(   { "_id" : 123,    /* other fields */,    "garbage" : someLongString})> collection.update(          ...
#   :(       ){         "_id" : BinData(5,"iiOI5R6P+dbut19O1mS1lA=="),         "reduce_id" : 0,                           ...
{    "_id" : id,    "name" : username,    "email" : email,    "phone" : phone,    "twitter" : username,                   ...
{    "_id" : id,    "name" : username,    “online”: {         "email" : email,         "twitter" : username,         ...  ...
# A           B                  C> db.coll.find({“A”: a, “B”: b, “C”: c})# C           B                  A> db.coll.find...
CA       A               A                B               B    C       C               C                    A            B...
C       C       C                A            B       B                    CA       A       A            B       B
> db.coll.ensureIndex({ A: 1 })> db.coll.ensureIndex({ B: 1 })> db.coll.ensureIndex({ C: 1 })# find   2   “Select A,B,C”> ...
journaling         :buildIndexes=false ReplicaSet             3                  AWSSingle Instance
Slave Delay              1journaling
Micro Instance Small Instance 32bit Large Instance        ArbiterSmall
$ ls /dbpath/rollbackdbname.collname.2011-08-14T18-27-14.0.bson$ bsondump dbname.collname.2011-08-14T18-27-14.0.bson { "_i...
DC1      PDC1                   S   P      DC2       Master                DC2
> db.collname.insert({_id:...})#> db.getLastError()# or> db.runCommand("getlasterror")
> db.runCommand({ getlasterror: 1, fsync: true }){ "err" : null, "n" : 0, "fsyncFiles" : 2, "ok" : 1 }> db.runCommand({ ge...
> db.getLastError(2, 5000) // w=2, timeout 5000ms> db.getLastError("majority")
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Upcoming SlideShare
Loading in...5
×

Advanced MongoDB #1

8,225

Published on

MongoDBのTipsや運用における注意点など、一歩進んだ内容を紹介します。書ききれないので#1です。

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

No Downloads
Views
Total Views
8,225
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
130
Comments
0
Likes
14
Embeds 0
No embeds

No notes for slide

Advanced MongoDB #1

  1. 1. Collection “product”: Collection “order”:{ { "_id" : productId1, "_id" : orderId, "name" : name1, "user" : userInfo, "price" : price1, "items" : [ "desc" : description1 productId1,}, productId2,{ productId3 "_id" : productId2, ]… }
  2. 2. Collection “product”: Collection “order”:{ { "_id" : productId1, "_id" : orderId, "name" : name1, "user" : userInfo, "price" : price1, "items" : [ "desc" : description1 productId1,} productId2,{ productId3> db.product.findOne(“_id”:productId1) "_id" : productId2, ]> db.product.findOne(“_id”:productId2)… }> db.product.findOne(“_id”:productId3)
  3. 3. Collection “order”:{ "_id" : orderId, "user" : userInfo, "items" : [ { "_id" : productId1, "name" : name1, "price" : price1 }, { "_id" : productId1, "name" : name1, "price" : price2 },... ] }
  4. 4. Collection “order”:{ order "_id" : orderId, "user" : userInfo, "items" : [ collection name { price order "_id" : productId1, "name" : name1, > db.order.find({ items :{ "price" : price1 $elemMatch: { name: name1 } }, { } } ) "_id" : productId1, "name" : name1, > db.order.find({ items :{ "price" : price2 $elemMatch: { price:{ $gt: 3000 } } },... } } ) ] }
  5. 5. Collection “order”: Collection “performance_rating”:{ { "_id" : orderId, "_id" : "employeeId", "user" : userInfo, "name" : "name", "items" : [ "post" : "section chief", { "abilities" : { "_id" : productId1, "skillA" : 20, "name" : name1, "skillC" : 12, "price" : price1 "skillE" : 18, }, { "skillF" : 24, "_id" : productId1, "skillG" : 23 "name" : name1, } "price" : price2 } },... ] }
  6. 6. Collection “order”: Collection “performance_rating”:{ { "_id" : orderId, "_id" : "employeeId",$elemMatch "user" : userInfo, "name" : "name", "items" : [ "post" : "section chief", { "abilities" : { "_id" : productId1, "skillA" : 20, "name" : name1, "skillC" : 12, "price" : price1 "skillE" : 18, }, { "skillF" : 24, "_id" : productId1, "skillG" : 23 "name" : name1, } 1 "price" : price2 } },... ”abilities.skillA” ] }
  7. 7. Collection “blog”:{ comment "_id" : blogId, "user" : userInfo, "tags" : [tag1, tag2, tag3] 16MB/document "comment": [{ In-Place "_id" : commentId1, "user" : userInfo1, "contents" : contents1 }, { "_id" : commentId2, "user" : userInfo2, "contents" : contents2 },... ] }
  8. 8. Collection “comment”:Collection “blog”: {{ "_id" : commentId, "_id" : blogId, "user" : userInfo, "user" : userInfo, > "contents" : contents1, db.comment.insert({ "tags" : [tag1, tag2, tag3] “_id”:commentId5, "lastUpdate" : datetime, "comment" : [ “user”:... ... commentId1, }) },... commentId3, { commentId5 "_id" : commentId5, ],... "user" : userInfo, }, "contents" : contents1,> db.blog.update({“_id”:blogId}, { "lastUpdate" : datetime,{$push: { “comment”: commentId5 }} ...}) }
  9. 9. > db.coll.stats(){ ... #1 "paddingFactor" : 1.4099999999940787, ...}
  10. 10. Collection “access_history”:{ "_id" : pageId, “start” 6 "start" : time, visitor "visits" : { "minutes" : [ “minites” [] [num0, num1, ..., num59], ( ) [num0, num1, ..., num59], [num0, num1, ..., num59], “minites” ”hours” [num0, num1, ..., num59], 0 [num0, num1, ..., num59], [num0, num1, ..., num59] ], "hours" : [num0, ..., num5] }}
  11. 11. Collection “access_history”:{ "_id" : pageId, "start" : time, "visits" : { "minutes" : [ [0,0, ..., 0], [0,0, ..., 0], [0,0, ..., 0], [0,0, ..., 0], [0,0, ..., 0], [0,0, ..., 0] ], "hours" : [0, ..., 0] }}
  12. 12. Collection “access_history”:{ "_id" : pageId, $inc "start" : time, "visits" : { "minutes" : [ [0,0, ..., 0], [3,0, ..., 0], > db.pages.update({ [0,0, ..., 0], "_id" : pageId, [0,0, ..., 0], "start" : thisHour },{ [0,0, ..., 0], "$inc": {"visits.minutes.1.0": 3} [0,0, ..., 0] }) ], "hours" : [0, ..., 0] }}
  13. 13. > collection.insert( { "_id" : 123, /* other fields */, "garbage" : someLongString})> collection.update( insert gabage { "_id": 123 }, { $unset: { "garbage" : 1} })
  14. 14. # :( ){ "_id" : BinData(5,"iiOI5R6P+dbut19O1mS1lA=="), "reduce_id" : 0, _id = user_id "user_id" : 00000, + date "date" : 20110727, + timeMilliSec + action_type "action_type" : "a{Make}", "key_depth" : 1, _id "action_detail" : { Binary "kakejiku" : 2, # Python "kaizokunojyuu" : 1, bson.Binary( "matoryo-sika" : 1, hashlib.md5( str(unique_id) "syokudai" : 1 ).digest(), } bson.binary.MD5_SUBTYPE )}
  15. 15. { "_id" : id, "name" : username, "email" : email, "phone" : phone, "twitter" : username, ”fax” "facebook" : username, "linkedin" : username, "google+" : number, "street" : street "city" : city, "state" : state, "zip" : zip, > db.profile.find({ "fax" : number “fax”: number })}
  16. 16. { "_id" : id, "name" : username, “online”: { "email" : email, "twitter" : username, ... }, ”address”: { ”telephone” "street" : street "city" : city, ... }, “telephone”: { "phone" : phone, > db.profile.find({ "fax" : number “telephone.fax”: number })}
  17. 17. # A B C> db.coll.find({“A”: a, “B”: b, “C”: c})# C B A> db.coll.find({“C”: c, “B”: b, “A”: a})# A B C> db.coll.find($or: [“A”: a, “B”: b, “C”: c])# C B A> db.coll.find($or: [“C”: c, “B”: b, “A”: a])
  18. 18. CA A A B B C C C A B B
  19. 19. C C C A B B CA A A B B
  20. 20. > db.coll.ensureIndex({ A: 1 })> db.coll.ensureIndex({ B: 1 })> db.coll.ensureIndex({ C: 1 })# find 2 “Select A,B,C”> db.coll.find({ A: a, B: b, C: c }, { _id: -1, A: 1, B: 1, C: 1 }) (_id ) Covered Index
  21. 21. journaling :buildIndexes=false ReplicaSet 3 AWSSingle Instance
  22. 22. Slave Delay 1journaling
  23. 23. Micro Instance Small Instance 32bit Large Instance ArbiterSmall
  24. 24. $ ls /dbpath/rollbackdbname.collname.2011-08-14T18-27-14.0.bson$ bsondump dbname.collname.2011-08-14T18-27-14.0.bson { "_id" : ... } { "_id" : ... } { "_id" : ... } Wed Aug 15 13:33:32 3 objects found
  25. 25. DC1 PDC1 S P DC2 Master DC2
  26. 26. > db.collname.insert({_id:...})#> db.getLastError()# or> db.runCommand("getlasterror")
  27. 27. > db.runCommand({ getlasterror: 1, fsync: true }){ "err" : null, "n" : 0, "fsyncFiles" : 2, "ok" : 1 }> db.runCommand({ getlasterror: 1, j: true })
  28. 28. > db.getLastError(2, 5000) // w=2, timeout 5000ms> db.getLastError("majority")
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×