JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
.gitignore
README.md
config.json
drop.js
find-brute.js
find-mapreduce-jsmode.js
find-mapreduce.js
find-mapreduce2-jsmode.js
find-mapreduce2.js
init-fixtures.js
package.json

README.md

Map/reduce on a single-instance MongoDB server

Source: http://naholyr.fr/2014/03/aggregation-mongodb-mono-instance-non/

Configure

Edit config.json to customize:

{
  "db": "mongodb://localhost/test-naholyr",
  "collection": "articles",
  "verbose": false,
  "nb_docs": 50000
}

Initialize

npm install
node init-fixtures

Run

Map/reduce (1 query)

node find-mapreduce

Sample output:

MapReduce: 901ms
Total: 903ms

Simpler map/reduce + find (2 queries)

node find-mapreduce2

Sample output:

MapReduce: 654ms
Find: 62ms
Total: 717ms

Find groups + 1 query per group (N+1 queries)

node find-brute

Sample output:

Authors: 308ms
Queries: 69ms
Total: 378ms

With jsMode: true

cf. http://docs.mongodb.org/manual/reference/method/db.collection.mapReduce/

Single map/reduce

node find-mapreduce-jsmode

Sample output:

MapReduce: 572ms
Total: 574ms

Simpler map/reduce + find

node find-mapreduce2

Sample output:

MapReduce: 445ms
Find: 55ms
Total: 501ms

Cleanup

node drop