0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/jstests/group2.js

39 lines
761 B
JavaScript
Raw Normal View History

2009-09-10 21:45:31 +02:00
t = db.group2;
t.drop();
t.save({a: 2});
t.save({b: 5});
t.save({a: 1});
2009-09-15 20:19:54 +02:00
cmd = { key: {a: 1},
initial: {count: 0},
reduce: function(obj, prev) {
prev.count++;
}
};
result = t.group(cmd);
2009-09-10 21:45:31 +02:00
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");
2009-09-15 20:19:54 +02:00
delete cmd.key
cmd["$keyf"] = function(x){ return { a : x.a }; };
result2 = t.group( cmd );
assert.eq( result , result2, "check result2" );
2009-10-20 17:13:33 +02:00
delete cmd.$keyf
cmd["keyf"] = function(x){ return { a : x.a }; };
result3 = t.group( cmd );
assert.eq( result , result3, "check result3" );