File: mrabench.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (61 lines) | stat: -rw-r--r-- 1,600 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
  In order to run this, you need to have a local copy of the usage data.

  One way to do this is to dump and restore it using mongodump and mongorestore
  */

db = db.getSiblingDB( "mongousage" )

function rollupMap() {
    emit( this._id.t , { total : this.value , unique : 1 } )
}

function rollupReduce(key, values) {
    var res = { total : 0 , unique : 0 };
    for ( var i=0; i<values.length; i++ ){
        res.total += values[i].total;
        res.unique += values[i].unique;
    }
    return res;
}

function mrrollups() {

    res = db.gen.monthly.ip.mapReduce( rollupMap , rollupReduce ,
				       { out : "gen.monthly" } )
    res.find().sort( { _id : -1 } ).forEach( printjsononeline )

    res = db.gen.weekly.ip.mapReduce( rollupMap , rollupReduce ,
				      { out : "gen.weekly" } )
    res.find().sort( { _id : -1 } ).forEach( printjsononeline )
}

function rollupMonthlyMR() {
    resMonthlyMR = db.gen.monthly.ip.mapReduce( rollupMap , rollupReduce ,
						{ out: { inline : 1 }} )
}

function rollupWeeklyMR() {
    resWeeklyMR = db.gen.weekly.ip.mapReduce( rollupMap , rollupReduce ,
					      { out : {inline : 1 }} )
}

function rollupMonthlyA() {
    resMonthlyA = db.runCommand( { aggregate: "gen.monthly.ip", pipeline : [
	{ $group : {
	    _id : { month: "_id.t" },
	    total : { $sum : "$value" },
	    unique : { $sum : 1 }
	}}
    ]});
}

function rollupWeeklyA() {
    resWeeklyA = db.runCommand( { aggregate: "gen.weekly.ip", pipeline : [
	{ $group : {
	    _id : { month: "_id.t" },
	    total : { $sum : "$value" },
	    unique : { $sum : 1 }
	}}
    ]});
}