Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

new stuff

  • Loading branch information...
commit 014a3679c24dcf9083118f53b3995d2e3b4b704a 1 parent ce46e1b
authored
82  aggregation/aggregation.md
Source Rendered
... ...
@@ -0,0 +1,82 @@
  1
+!SLIDE
  2
+
  3
+## Aggregation
  4
+
  5
+!SLIDE
  6
+
  7
+## Grouping
  8
+
  9
+    @@@javascript
  10
+    > db.events.group({
  11
+      key: {speaker: true},
  12
+      inital: {count: 0},
  13
+      reduce: function(doc, prev){
  14
+        prev.count++;
  15
+      }
  16
+    });
  17
+    
  18
+    // Result
  19
+    [{
  20
+      "speaker": "Adam Holt",
  21
+      "count": 1
  22
+    }]
  23
+
  24
+!SLIDE
  25
+
  26
+## MapReduce
  27
+
  28
+    @@@javascript
  29
+    > map = function(){
  30
+      this.tags.forEach(
  31
+        function(tag){
  32
+          emit( tag , { count : 1 } );
  33
+        }
  34
+      );
  35
+    }
  36
+    > reduce = function(key, values){
  37
+      var total = 0;
  38
+      for(var i=0;i<values.length;i++)
  39
+        total += values[i].count;
  40
+      return {count: total};
  41
+    }
  42
+    > res = db.events.mapReduce(map, reduce);
  43
+    
  44
+!SLIDE
  45
+
  46
+## MapReduce Results
  47
+
  48
+    @@@javascript
  49
+    {
  50
+      "result": "tmp.mr.mapreduce_1276726664_3",
  51
+      "timeMillis": 90,
  52
+      "counts": {
  53
+        "input": 1,
  54
+        "emit": 4,
  55
+        "output": 4
  56
+      },
  57
+      "ok" : 1,
  58
+    }
  59
+
  60
+!SLIDE    
  61
+
  62
+## Getting the results
  63
+    
  64
+    @@@javascript
  65
+    > db[res.result].find()
  66
+    { 
  67
+      "_id": "mongodb", 
  68
+      "value": { "count" : 1 } 
  69
+    }
  70
+    { 
  71
+      "_id": "mongoid", 
  72
+      "value": { "count" : 1 } 
  73
+    }
  74
+    { 
  75
+      "_id": "nwrug", 
  76
+      "value": { "count" : 1 } 
  77
+    }
  78
+    { 
  79
+      "_id": "ruby", 
  80
+      "value": { "count" : 1 } 
  81
+    }
  82
+    
4  binary_data_storage/binary_data_storage.md
Source Rendered
... ...
@@ -1,4 +0,0 @@
1  
-!SLIDE
2  
-
3  
-## Binary Data Storage
4  
-## GridFS
111  dynamic_queries/dynamic_queries.md
Source Rendered
@@ -7,15 +7,108 @@
7 7
 ## Find a Document!
8 8
 
9 9
     @@@javascript
10  
-    db.events.find();
11  
-    db.events.find({
12  
-      "name" : "NWRUG - MongoDB is Awesome!"
  10
+    > db.events.find();
  11
+    > db.events.find({
  12
+      name : "NWRUG - MongoDB is Awesome!"
13 13
     });
14  
-    db.events.find({
15  
-      "tags" : {"$in" : ["mongodb", "ruby"]}
  14
+    > db.events.find({
  15
+      tags : {$in : ["mongodb", "ruby"]}
16 16
     });
17  
-    db.events.find({
18  
-      "attendees" : {
19  
-        "$gt" : 10
  17
+    > db.events.find({
  18
+      attendees : {
  19
+        $gt : 10
20 20
       }
21  
-    });
  21
+    });
  22
+
  23
+!SLIDE center smbullets
  24
+
  25
+## Query Operators
  26
+
  27
+* $lt
  28
+* $gt
  29
+* $lte
  30
+* $gte
  31
+* $ne
  32
+* $in
  33
+* $nin
  34
+
  35
+!SLIDE center smbullets
  36
+
  37
+## More Query Operators
  38
+
  39
+* $mod
  40
+* $all
  41
+* $size
  42
+* $exists
  43
+* $type
  44
+* $elemMatch
  45
+* $not
  46
+
  47
+!SLIDE
  48
+
  49
+## Find by embedded document
  50
+  
  51
+### Dot Notation
  52
+  
  53
+    @@@javascript
  54
+    > db.events.find({
  55
+      "comments.user" : "@willj"
  56
+    });
  57
+    > db.events.find({
  58
+      "comments.0.user" : "@willj"
  59
+    });
  60
+
  61
+!SLIDE
  62
+
  63
+## Find by embedded document
  64
+
  65
+### Sub Documents
  66
+
  67
+    @@@javascript
  68
+    // This will not find our document!
  69
+    > db.events.find({
  70
+      comments : {
  71
+        user : "@adamholt"
  72
+      }
  73
+    });
  74
+    // This will!
  75
+    > db.events.find({
  76
+      comments : {
  77
+        user : "@adamholt", 
  78
+        comment : "I <3 MongoDB!"
  79
+      }
  80
+    });
  81
+
  82
+### Sub Document matching only works on exact matches
  83
+
  84
+!SLIDE
  85
+
  86
+## A Word about $elemMatch
  87
+
  88
+### $elemMatch will match the entire document within an array
  89
+
  90
+    @@@javascript
  91
+    > db.events.find({
  92
+      "comments.user" : "@spammer",
  93
+      "comments.comment" : /^viagra/i
  94
+    });
  95
+    
  96
+    > db.events.find({
  97
+      comments : {
  98
+        $elemMatch : {
  99
+          user : "@spammer",
  100
+          comment : /^viagra/i
  101
+        }
  102
+      }
  103
+    });
  104
+    
  105
+!SLIDE
  106
+  
  107
+## Counting, Skipping and Limiting
  108
+  
  109
+    @@@javascript
  110
+    > db.events.find().sort({attendees : 1});
  111
+    > db.events.find().sort({attendees : 1});
  112
+    > db.events.find().limit(10);
  113
+    > db.events.find().skip(10);
  114
+    > db.events.find().count();
24  embedded_documents/embedded_documents.md
Source Rendered
... ...
@@ -0,0 +1,24 @@
  1
+!SLIDE title center
  2
+
  3
+# Embedded Documents
  4
+
  5
+!SLIDE
  6
+
  7
+## Create a document
  8
+
  9
+    @@@javascript
  10
+    > db.events.insert({
  11
+      name : "NWRUG - MongoDB is Awesome!",
  12
+      tags : ["mongodb", "ruby", "nwrug"],
  13
+      attendees : 25,
  14
+      comments : [{
  15
+          user : "@willj",
  16
+          comment : 
  17
+            "I'm gonna use MongoDB for all my 
  18
+            projects! Screw Postgres!"
  19
+        },
  20
+        {
  21
+          user : "@adamholt",
  22
+          comment : "I <3 MongoDB!"
  23
+      }]
  24
+    });
38  getting_started/getting_started.md
Source Rendered
@@ -6,19 +6,39 @@
6 6
 
7 7
 # Install! #
8 8
 
9  
-    $curl http://downloads.mongodb.org/osx/mongodb-osx-i386-1.4.3.tgz > mongodb-osx-i386-1.4.3.tgz
10  
-    $tar -xzvf mongodb-osx-i386-1.4.3.tgz
11  
-    $mkdir -p /data/db # create the mongodb data dir
12  
-    $cd mongodb-osx-i386-1.4.3
13  
-    $./bin/mongod # start mongodb
  9
+    $ curl http://downloads.mongodb.org/osx/mongodb-osx-i386-1.4.3.tgz > mongodb-osx-i386-1.4.3.tgz
  10
+    $ tar -xzvf mongodb-osx-i386-1.4.3.tgz
  11
+    $ mkdir -p /data/db # create the mongodb data dir
  12
+    $ ./mongodb-osx-i386-1.4.3/bin/mongod # start mongodb
  13
+
  14
+!SLIDE commandline
  15
+
  16
+# Mongo Console #
  17
+
  18
+    $ ./mongo-osx-i386-1.4.3/bin/mongo
  19
+
  20
+!SLIDE smbullets
  21
+
  22
+# Terminology
  23
+
  24
+* Database == Database
  25
+* Collection == Table
  26
+* Document == Row
14 27
 
15 28
 !SLIDE
16 29
 
  30
+# Setup your Database #
  31
+
  32
+    @@@javascript
  33
+    > use nwrug-mongodb
  34
+    switched to db nwrug-mongodb
  35
+
  36
+!SLIDE
17 37
 # Create a Document! #
18 38
 
19 39
     @@@javascript
20  
-    db.events.insert({
21  
-      "name" : "NWRUG - MongoDB is Awesome!",
22  
-      "tags" : ["mongodb", "ruby", "nwrug"],
23  
-      "attendees" : 25
  40
+    > db.events.insert({
  41
+      name : "NWRUG - MongoDB is Awesome!",
  42
+      tags : ["mongodb", "ruby", "nwrug"],
  43
+      attendees : 25
24 44
     });
94  in_place_updates/in_place_updates.md
Source Rendered
... ...
@@ -1,3 +1,95 @@
1 1
 !SLIDE
2 2
 
3  
-## In-place Updates
  3
+## In-place Updates
  4
+
  5
+!SLIDE
  6
+
  7
+## Update
  8
+
  9
+    @@@javascript
  10
+    > db.events.update(
  11
+      { name: "NWRUG - MongoDB is Awesome!"},
  12
+      { 
  13
+        "name" : "NWRUG - MongoDB is Awesome!",
  14
+        "tags" : [
  15
+          "mongodb", 
  16
+          "ruby", 
  17
+          "nwrug", 
  18
+          "awesome"
  19
+        ],
  20
+        "attendees" : 25,
  21
+      }
  22
+    );
  23
+    
  24
+!SLIDE
  25
+
  26
+## Upsert
  27
+
  28
+    @@@javascript
  29
+    > db.events.update(
  30
+      { name: "NWRUG - MacRuby by Caius?"},
  31
+      { 
  32
+        "name" : "NWRUG - MacRuby by Caius?",
  33
+        "tags" : [
  34
+          "mac", 
  35
+          "ruby", 
  36
+          "nwrug", 
  37
+          "macruby"
  38
+        ],
  39
+        "attendees" : 25,
  40
+      },
  41
+      true
  42
+    );
  43
+    
  44
+!SLIDE
  45
+
  46
+## Modifier Operations
  47
+
  48
+    @@@javascript
  49
+    > db.events.update(
  50
+      { name: "NWRUG - MongoDB is Awesome!"},
  51
+      {$inc: {attendees: 1}}
  52
+    );
  53
+    > db.events.update(
  54
+      { name: "NWRUG - MongoDB is Awesome!"},
  55
+      {$dec: {attendees: 1}}
  56
+    );
  57
+    
  58
+!SLIDE
  59
+
  60
+## More Modifier Operations
  61
+    
  62
+    @@@javascript
  63
+    > db.events.update(
  64
+      { name: "NWRUG - MongoDB is Awesome!"},
  65
+      {$set: {speaker: "Adam Holt"}}
  66
+    );
  67
+    > db.events.update(
  68
+      { name: "NWRUG - MongoDB is Awesome!"},
  69
+      {$unset: {attendees: 1}
  70
+    );
  71
+    
  72
+!SLIDE
  73
+
  74
+## More Modifier Operations
  75
+
  76
+    @@@javascript
  77
+    > db.events.update(
  78
+      { name: "NWRUG - MongoDB is Awesome!"},
  79
+      {$push: {tags: "mongoid"}}
  80
+    );
  81
+    > db.events.update(
  82
+      { name: "NWRUG - MongoDB is Awesome!"},
  83
+      {$pull: {tags: "awesome"}}
  84
+    );
  85
+
  86
+!SLIDE
  87
+
  88
+## Positional Operator
  89
+
  90
+
  91
+    @@@javascript
  92
+    > db.events.update(
  93
+      {"comments.user": "@adamholt"},
  94
+      {$inc : {"comments.$.votes" : 1}}
  95
+    );
73  indexes/indexes.md
Source Rendered
... ...
@@ -1,3 +1,74 @@
1 1
 !SLIDE
2 2
 
3  
-## Index Support
  3
+## Indexes
  4
+
  5
+!SLIDE
  6
+
  7
+## Add Indexes
  8
+
  9
+    @@@javascript
  10
+    > db.events.ensureIndex({name: 1})
  11
+    > db.events.ensureIndex({tags: -1})
  12
+    > db.events.ensureIndex({
  13
+      "comments.user": 1
  14
+    })
  15
+    > db.events.ensureIndex({attendees: 1},
  16
+      {background: true})
  17
+    > db.events.ensureIndex({name: 1},
  18
+      {unique: true})
  19
+    > db.events.ensureIndex({
  20
+      name: 1, attendees: -1
  21
+    })
  22
+    
  23
+!SLIDE    
  24
+
  25
+## Remove Indexes
  26
+
  27
+    @@@javascript
  28
+    > db.events.dropIndex({name: 1})
  29
+    > db.events.dropIndexes()
  30
+
  31
+!SLIDE
  32
+
  33
+## Give me a hint!
  34
+    
  35
+    @@@javascript
  36
+    > db.events.find(
  37
+      {tags: "ruby"}
  38
+    ).hint({tags: -1})
  39
+    
  40
+!SLIDE
  41
+
  42
+## Geospatial Indexes
  43
+
  44
+### Add a location to my event
  45
+
  46
+    @@@javascript
  47
+    > db.events.update(
  48
+      {name: "NWRUG - MongoDB is Awesome!"}, 
  49
+      {$set: {loc: [53.47405,-2.238657]}}
  50
+    )
  51
+
  52
+### Add a 2D Index
  53
+
  54
+    @@@javascript
  55
+    > db.events.ensureIndex({loc: "2d"})
  56
+
  57
+!SLIDE
  58
+
  59
+## Find My Events!
  60
+
  61
+    @@@javascript
  62
+    > db.events.find({
  63
+      loc: {
  64
+        $near: [53.474038,-2.242005]
  65
+      }
  66
+    })
  67
+    > db.events.find({loc: {
  68
+      $within: {
  69
+        $box: [
  70
+          [53.47041,-2.246404],
  71
+          [53.477377,-2.231072]
  72
+        ]
  73
+      }
  74
+    }})
3  map_reduce/map_reduce.md
Source Rendered
... ...
@@ -1,3 +0,0 @@
1  
-!SLIDE
2  
-
3  
-## MapReduce
BIN  overview/companies.png
BIN  overview/companies.pxm
Binary file not shown
2  overview/overview.md
Source Rendered
@@ -22,5 +22,5 @@
22 22
 
23 23
 !SLIDE center
24 24
 
25  
-# Who Uses MongoDB? ##
  25
+# Who Uses MongoDB? #
26 26
 ![Who Uses MongoDB](companies.png)
27  query_profiling/query_profiling.md
Source Rendered
... ...
@@ -1,3 +1,28 @@
1 1
 !SLIDE
2 2
 
3  
-## Query Profiling
  3
+## Query Profiling
  4
+
  5
+    @@@javascript
  6
+    > db.events.find({tags: "ruby"}).explain();
  7
+
  8
+!SLIDE
  9
+    
  10
+    @@@javascript
  11
+    {
  12
+      "cursor" : "BasicCursor",
  13
+      "indexBounds" : [ ],
  14
+      "nscanned" : 1,
  15
+      "nscannedObjects" : 1,
  16
+      "n" : 1,
  17
+      "millis" : 22,
  18
+      "oldPlan" : {
  19
+        "cursor" : "BasicCursor",
  20
+        "indexBounds" : [ ]
  21
+      },
  22
+      "allPlans" : [
  23
+        {
  24
+          "cursor" : "BasicCursor",
  25
+          "indexBounds" : [ ]
  26
+        }
  27
+      ]
  28
+    }
3  sharding/sharding.md
Source Rendered
... ...
@@ -1,3 +0,0 @@
1  
-!SLIDE
2  
-
3  
-## Auto-sharding
9  showoff.json
... ...
@@ -1,11 +1,10 @@
1 1
 [
2 2
   {"section":"overview"},
3 3
   {"section":"getting_started"},
  4
+  {"section":"embedded_documents"},
4 5
   {"section":"dynamic_queries"},
5  
-  {"section":"indexes"},
6 6
   {"section":"in_place_updates"},
7  
-  {"section":"map_reduce"},
8  
-  {"section":"query_profiling"},
9  
-  {"section":"binary_data_storage"},
10  
-  {"section":"sharding"}
  7
+  {"section":"indexes"},
  8
+  {"section":"aggregation"},
  9
+  {"section":"query_profiling"}
11 10
 ]

0 notes on commit 014a367

Please sign in to comment.
Something went wrong with that request. Please try again.