Files
mongo/jstests/aggregation/bugs/server6361.js
Mathias Stearn 061a086641 SERVER-10165 aggregate() shell helper now returns a cursor
The actual change is in src/mongo/shell/collection.js with the remaining changes
to adjust tests to the new api.

The "ideal" arguments are now an array of pipeline ops and an optional object
with extra top-level options for the command (such as {explain: true}. For
backwards compatibility, we still support the varargs style where each argument
is a pipeline stage, but there is no way to specify extra parameters in this
mode.
2013-10-08 17:35:02 -04:00

28 lines
766 B
JavaScript

// SERVER-6361 Disallow exclusions in $project for 2.2
// load the test utilities
load('jstests/aggregation/extras/utils.js');
c = db.c;
c.drop();
c.insert({a:2, nested: {_id:2, other:2}});
assertErrorCode(c, {$project: {a:0}}, 16406);
// excluding top-level _id is still allowed
res = c.aggregate({$project: {_id:0, a:1}});
assert.eq(res.toArray()[0], {a:2});
// excluding nested _id is not
assertErrorCode(c, {$project: {'nested._id':0}}, 16406);
// nested _id is not automatically included
res = c.aggregate({$project: {_id:0, 'nested.other':1}})
assert.eq(res.toArray()[0], {nested: {other:2}});
// not including anything is an error
assertErrorCode(c, {$project: {}}, 16403);
// even if you exclude _id
assertErrorCode(c, {$project: {'_id':0}}, 16403);