SlideShare a Scribd company logo
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Collection “product”:        Collection “order”:
{                            {
     "_id" : productId1,         "_id" : orderId,
     "name" : name1,             "user" : userInfo,
     "price" : price1,           "items" : [
     "desc" : description1           productId1,
},                                   productId2,
{                                    productId3
     "_id" : productId2,         ]
…                            }
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)
Collection “order”:
{
    "_id" : orderId,
    "user" : userInfo,
    "items" : [
          {
              "_id" : productId1,
              "name" : name1,
              "price" : price1
          }, {
              "_id" : productId1,
              "name" : name1,
              "price" : price2
          },...
    ] }
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 } }

          },...                     } } )

    ] }
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      }
          },...
    ] }
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”
    ] }
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
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
          },...
    ] }
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 }}
                                          ...
})
                                     }
Advanced MongoDB #1
> db.coll.stats()
{   ...
    #1

    "paddingFactor" : 1.4099999999940787,
    ...
}
Advanced MongoDB #1
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] }
}
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] }
}
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] }
}
> collection.insert(
   { "_id" : 123,
    /* other fields */,
    "garbage" : someLongString})
> collection.update(
                          insert   gabage
   { "_id": 123 },
   { $unset: { "garbage" : 1} })
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
#   :(       )

{
         "_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
                                         )
}
Advanced MongoDB #1
Advanced MongoDB #1
{
    "_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
                               })
}
Advanced MongoDB #1
{
    "_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
                                   })
}
Advanced MongoDB #1
Advanced MongoDB #1
# 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])
C

A       A               A
                B               B




    C       C               C
                    A
            B               B
C       C       C
                A
            B       B




                    C

A       A       A
            B       B
Advanced MongoDB #1
> 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
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
journaling


         :buildIndexes=false


 ReplicaSet             3
                  AWS
Single Instance
Slave Delay




              1
journaling
Micro Instance


 Small Instance
 32bit
 Large Instance


        Arbiter


Small
Advanced MongoDB #1
$ ls /dbpath/rollback
dbname.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
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
Advanced MongoDB #1
DC1      P
DC1                   S   P
      DC2
       Master
                DC2
Advanced MongoDB #1
> 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({ getlasterror: 1, j: true })
> 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

More Related Content

PDF
2013-03-23 - NoSQL Spartakiade
PDF
MongoD Essentials
PDF
Spine JS
PDF
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
PPTX
MongoDB Online Conference: Introducing MongoDB 2.2
PDF
Dig Deeper into WordPress - WD Meetup Cairo
PDF
MongoDB With Style
PDF
Groovy scripts with Groovy
2013-03-23 - NoSQL Spartakiade
MongoD Essentials
Spine JS
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB Online Conference: Introducing MongoDB 2.2
Dig Deeper into WordPress - WD Meetup Cairo
MongoDB With Style
Groovy scripts with Groovy

What's hot (18)

PPTX
JavaScript Objects and OOP Programming with JavaScript
PDF
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
PDF
Dojo >= 1.7 Kickstart
PDF
Desarrollo de módulos en Drupal e integración con dispositivos móviles
PPTX
Schema Design
PDF
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
PDF
Ruby Development and MongoMapper (John Nunemaker)
PPTX
Mongo db mug_2012-02-07
PDF
From mysql to MongoDB(MongoDB2011北京交流会)
PDF
The Ring programming language version 1.5.1 book - Part 42 of 180
PPTX
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
PDF
Cleaner, Leaner, Meaner: Refactoring your jQuery
PPTX
Object oriented javascript
PDF
Couchbase Korea User Group 2nd Meetup #2
PDF
Command-Oriented Architecture
PDF
Building DSLs with Groovy
PPT
Kick start with j query
KEY
Mongo db presentation
JavaScript Objects and OOP Programming with JavaScript
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
Dojo >= 1.7 Kickstart
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Schema Design
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
Ruby Development and MongoMapper (John Nunemaker)
Mongo db mug_2012-02-07
From mysql to MongoDB(MongoDB2011北京交流会)
The Ring programming language version 1.5.1 book - Part 42 of 180
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Cleaner, Leaner, Meaner: Refactoring your jQuery
Object oriented javascript
Couchbase Korea User Group 2nd Meetup #2
Command-Oriented Architecture
Building DSLs with Groovy
Kick start with j query
Mongo db presentation
Ad

Viewers also liked (14)

PPTX
MongoDBが遅いときの切り分け方法
PDF
Mongodb 紹介
PDF
ソーシャルゲームにおけるMongoDB適用事例 - Animal Land
PPTX
MongoDB on EC2 #mongodbcasual
PPTX
日本語:Mongo dbに於けるシャーディングについて
PDF
Mongo dbを知ろう devlove関西
KEY
カジュアルにソースコードリーディング
PDF
CasualなMongoDBのサービス運用Tips
PDF
Casual Compression on MongoDB
PDF
MongoDBではじめるカジュアルなタイムラインシステム
PDF
カジュアルにMongo dbのbackup機能説明
PPTX
Mongo dbを知ろう
PDF
MongoDB〜その性質と利用場面〜
PDF
MongoDBのアレをアレする
MongoDBが遅いときの切り分け方法
Mongodb 紹介
ソーシャルゲームにおけるMongoDB適用事例 - Animal Land
MongoDB on EC2 #mongodbcasual
日本語:Mongo dbに於けるシャーディングについて
Mongo dbを知ろう devlove関西
カジュアルにソースコードリーディング
CasualなMongoDBのサービス運用Tips
Casual Compression on MongoDB
MongoDBではじめるカジュアルなタイムラインシステム
カジュアルにMongo dbのbackup機能説明
Mongo dbを知ろう
MongoDB〜その性質と利用場面〜
MongoDBのアレをアレする
Ad

Similar to Advanced MongoDB #1 (20)

PDF
Modern Application Foundations: Underscore and Twitter Bootstrap
PPTX
Webinar: Strongly Typed Languages and Flexible Schemas
PPTX
Build your own entity with Drupal
PPTX
Authentication Users for data accessing in collections for it.pptx
PPTX
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
PDF
Your Entity, Your Code
PDF
Your Entity, Your Code
PDF
Sencha Touch meets TYPO3
PDF
MongoDB Performance Tuning
PPTX
Back to Basics 2017 - Your First MongoDB Application
PPTX
Back to Basics: My First MongoDB Application
PPTX
MongoDB World 2018: Keynote
PPTX
Building a Scalable Inbox System with MongoDB and Java
PPTX
1403 app dev series - session 5 - analytics
PDF
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
PDF
Strongly Typed Languages and Flexible Schemas
PDF
MongoDB Aggregation Framework in action !
PPTX
Query for json databases
PPTX
Back to basics Italian webinar 2 Mia prima applicazione MongoDB
PPTX
MongoDB - Back to Basics - La tua prima Applicazione
Modern Application Foundations: Underscore and Twitter Bootstrap
Webinar: Strongly Typed Languages and Flexible Schemas
Build your own entity with Drupal
Authentication Users for data accessing in collections for it.pptx
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
Your Entity, Your Code
Your Entity, Your Code
Sencha Touch meets TYPO3
MongoDB Performance Tuning
Back to Basics 2017 - Your First MongoDB Application
Back to Basics: My First MongoDB Application
MongoDB World 2018: Keynote
Building a Scalable Inbox System with MongoDB and Java
1403 app dev series - session 5 - analytics
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
Strongly Typed Languages and Flexible Schemas
MongoDB Aggregation Framework in action !
Query for json databases
Back to basics Italian webinar 2 Mia prima applicazione MongoDB
MongoDB - Back to Basics - La tua prima Applicazione

More from Takahiro Inoue (20)

PDF
Treasure Data × Wave Analytics EC Demo
PDF
トレジャーデータとtableau実現する自動レポーティング
PDF
Tableauが魅せる Data Visualization の世界
PDF
トレジャーデータのバッチクエリとアドホッククエリを理解する
PDF
20140708 オンラインゲームソリューション
PDF
トレジャーデータ流,データ分析の始め方
PDF
オンラインゲームソリューション@トレジャーデータ
PDF
事例で学ぶトレジャーデータ 20140612
PDF
トレジャーデータ株式会社について(for all Data_Enthusiast!!)
PDF
この Visualization がすごい2014 〜データ世界を彩るツール6選〜
PDF
Treasure Data Intro for Data Enthusiast!!
PDF
Hadoop and the Data Scientist
PDF
MongoDB: Intro & Application for Big Data
PDF
An Introduction to Fluent & MongoDB Plugins
PDF
An Introduction to Tinkerpop
PDF
An Introduction to Neo4j
PDF
The Definition of GraphDB
PDF
Large-Scale Graph Processing〜Introduction〜(完全版)
PDF
Large-Scale Graph Processing〜Introduction〜(LT版)
PDF
はじめてのGlusterFS
Treasure Data × Wave Analytics EC Demo
トレジャーデータとtableau実現する自動レポーティング
Tableauが魅せる Data Visualization の世界
トレジャーデータのバッチクエリとアドホッククエリを理解する
20140708 オンラインゲームソリューション
トレジャーデータ流,データ分析の始め方
オンラインゲームソリューション@トレジャーデータ
事例で学ぶトレジャーデータ 20140612
トレジャーデータ株式会社について(for all Data_Enthusiast!!)
この Visualization がすごい2014 〜データ世界を彩るツール6選〜
Treasure Data Intro for Data Enthusiast!!
Hadoop and the Data Scientist
MongoDB: Intro & Application for Big Data
An Introduction to Fluent & MongoDB Plugins
An Introduction to Tinkerpop
An Introduction to Neo4j
The Definition of GraphDB
Large-Scale Graph Processing〜Introduction〜(完全版)
Large-Scale Graph Processing〜Introduction〜(LT版)
はじめてのGlusterFS

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Empathic Computing: Creating Shared Understanding
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Electronic commerce courselecture one. Pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
A Presentation on Artificial Intelligence
PPTX
1. Introduction to Computer Programming.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Spectral efficient network and resource selection model in 5G networks
Empathic Computing: Creating Shared Understanding
NewMind AI Weekly Chronicles - August'25-Week II
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Assigned Numbers - 2025 - Bluetooth® Document
MYSQL Presentation for SQL database connectivity
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Electronic commerce courselecture one. Pdf
Spectroscopy.pptx food analysis technology
A comparative analysis of optical character recognition models for extracting...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Big Data Technologies - Introduction.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
A Presentation on Artificial Intelligence
1. Introduction to Computer Programming.pptx
Network Security Unit 5.pdf for BCA BBA.
Diabetes mellitus diagnosis method based random forest with bat algorithm

Advanced MongoDB #1

  • 9. Collection “product”: Collection “order”: { { "_id" : productId1, "_id" : orderId, "name" : name1, "user" : userInfo, "price" : price1, "items" : [ "desc" : description1 productId1, }, productId2, { productId3 "_id" : productId2, ] … }
  • 10. 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)
  • 11. Collection “order”: { "_id" : orderId, "user" : userInfo, "items" : [ { "_id" : productId1, "name" : name1, "price" : price1 }, { "_id" : productId1, "name" : name1, "price" : price2 },... ] }
  • 12. 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 } } },... } } ) ] }
  • 13. 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 } },... ] }
  • 14. 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” ] }
  • 18. 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 },... ] }
  • 19. 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 }} ... }) }
  • 21. > db.coll.stats() { ... #1 "paddingFactor" : 1.4099999999940787, ... }
  • 23. 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] } }
  • 24. 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] } }
  • 25. 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] } }
  • 26. > collection.insert( { "_id" : 123, /* other fields */, "garbage" : someLongString}) > collection.update( insert gabage { "_id": 123 }, { $unset: { "garbage" : 1} })
  • 30. # :( ) { "_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 ) }
  • 33. { "_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 }) }
  • 35. { "_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 }) }
  • 38. # 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])
  • 39. C A A A B B C C C A B B
  • 40. C C C A B B C A A A B B
  • 42. > 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
  • 47. journaling :buildIndexes=false ReplicaSet 3 AWS Single Instance
  • 48. Slave Delay 1 journaling
  • 49. Micro Instance Small Instance 32bit Large Instance Arbiter Small
  • 51. $ ls /dbpath/rollback dbname.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
  • 57. DC1 P DC1 S P DC2 Master DC2
  • 59. > db.collname.insert({_id:...}) # > db.getLastError() # or > db.runCommand("getlasterror")
  • 60. > db.runCommand({ getlasterror: 1, fsync: true }) { "err" : null, "n" : 0, "fsyncFiles" : 2, "ok" : 1 } > db.runCommand({ getlasterror: 1, j: true })
  • 61. > db.getLastError(2, 5000) // w=2, timeout 5000ms > db.getLastError("majority")