Files
mongo/jstests/core/group8.js
Jason Rassi 3c23add370 SERVER-14099 Add GroupStage query execution stage
getExecutorGroup() is now the main entry point for execution of a
group operation.
2014-09-08 20:30:18 -04:00

26 lines
988 B
JavaScript

// Test correctness of the "keys" and and "count" fields in the group command output.
var coll = db.group8;
var result;
coll.drop();
assert.writeOK(coll.insert({a: 1, b: "x"}));
assert.writeOK(coll.insert({a: 2, b: "x"}));
assert.writeOK(coll.insert({a: 2, b: "x"}));
assert.writeOK(coll.insert({a: 3, b: "y"}));
// Test case when "count" and "keys" are both zero.
result = coll.runCommand({group: {ns: coll.getName(), key: {a: 1}, cond: {b: "z"},
$reduce: function(x, y) {}, initial: {}}});
assert.commandWorked(result);
assert.eq(result.count, 0);
assert.eq(result.keys, 0);
assert.eq(result.retval.length, 0);
// Test case when "count" and "keys" are both non-zero.
result = coll.runCommand({group: {ns: coll.getName(), key: {a: 1}, cond: {b: "x"},
$reduce: function(x, y) {}, initial: {}}});
assert.commandWorked(result);
assert.eq(result.count, 3);
assert.eq(result.keys, 2);
assert.eq(result.retval.length, 2);