summaryrefslogtreecommitdiff
path: root/jstests/core/group2.js
blob: a8e6653470a8446b4b43ad0cb81101eb3fca0bcd (plain)
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
t = db.group2;
t.drop();

t.save({a: 2});
t.save({b: 5});
t.save({a: 1});

cmd = { key: {a: 1},
        initial: {count: 0},
        reduce: function(obj, prev) {
            prev.count++;
        }
      };

result = t.group(cmd);

assert.eq(3, result.length, "A");
assert.eq(null, result[1].a, "C");
assert("a" in result[1], "D");
assert.eq(1, result[2].a, "E");

assert.eq(1, result[0].count, "F");
assert.eq(1, result[1].count, "G");
assert.eq(1, result[2].count, "H");


delete cmd.key
cmd["$keyf"] = function(x){ return { a : x.a }; };
result2 = t.group( cmd );

assert.eq( result , result2, "check result2" );


delete cmd.$keyf
cmd["keyf"] = function(x){ return { a : x.a }; };
result3 = t.group( cmd );

assert.eq( result , result3, "check result3" );