Permalink
Browse files

Update 06 - mongodb.md

  • Loading branch information...
1 parent 04ce1cb commit f4824393b40bedd9f68816c10fc4f3c32c611189 @duarten committed Feb 12, 2013
Showing with 16 additions and 16 deletions.
  1. +16 −16 06 - mongodb.md
View
@@ -38,7 +38,7 @@ Implicitly defined in the application(s).
**How do we list the documents in a collection?**
- db.coll.find()
+ db.blog.find()
* * *
@@ -57,42 +57,42 @@ Here you go:
```javascript
(function() {
var titlePrefix = ['Some', 'More', 'About', 'Consider The'],
- titleSuffix = ['Stuff', 'Things', 'Problems'],
- tags = ['omg', 'humm', 'wtf'],
- upvoteDelta = 16,
- maxDocuments = 10,
- rand = function(max) { return Math.floor(Math.random() * max); },
- decide = function(what) { return rand(2) > 0; },
- i;
+ titleSuffix = ['Stuff', 'Things', 'Problems'],
+ tags = ['omg', 'humm', 'wtf'],
+ upvoteDelta = 16,
+ maxDocuments = 10,
+ rand = function(max) { return Math.floor(Math.random() * max); },
+ tossCoin = function() { return rand(2) > 0; },
+ i;
for (i = 0; i < maxDocuments; ++i) {
var doc = {
title: titlePrefix[rand(titlePrefix.length)] + ' ' + titleSuffix[rand(titleSuffix.length)],
content: 'Yadda, yadda, yadda',
date: (function(d) { return new Date(d.setDate(d.getDate() + rand(maxDocuments))); })(new Date()),
- upvotes: rand(upvoteDelta) * (decide('if negative') ? 1 : -1),
+ upvotes: rand(upvoteDelta) * tossCoin() ? 1 : -1,
tags: (function() {
var n = rand(tags.length),
ts = tags.length;
return n > 1 ? randInts(n, ts).map(function(i) { return tags[i]; }) : tags[rand(ts)];
})()
};
- if (decide('has comments'))
+ if (tossCoin())
doc.comments = ['Some Comment', 'Another Comment'];
- db.blog.insert(doc);
- }
+ db.blog.insert(doc);
+ }
- function randInts(howMany, maxValue) {
- var values = new Array(howMany),
- i;
+ function randInts(howMany, maxValue) {
+ var values = new Array(howMany),
+ i;
for (i = 0; i < howMany; ++i)
values[i] = rand(maxValue);
return values;
- }
+ }
})();
```

0 comments on commit f482439

Please sign in to comment.