Files
mongo/jstests/aggregation/bugs/server6195.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

36 lines
2.0 KiB
JavaScript

// ensure $concat asserts on string
load('jstests/aggregation/extras/utils.js')
c = db.s6570;
c.drop();
c.save({v:"$", w:".", x:"foo", y:"bar"});
assert.eq(c.aggregate({$project:{str:{$concat:["X", "$x", "Y", "$y"]}}}).toArray()[0].str, "XfooYbar");
assert.eq(c.aggregate({$project:{str:{$concat:["$v", "X", "$w", "Y"]}}}).toArray()[0].str, "$X.Y");
assert.eq(c.aggregate({$project:{str:{$concat:["$w", "X", "$v", "Y"]}}}).toArray()[0].str, ".X$Y");
// Nullish (both with and without other strings)
assert.isnull(c.aggregate({$project:{str:{$concat: ["$missing"] }}}).toArray()[0].str);
assert.isnull(c.aggregate({$project:{str:{$concat: [null] }}}).toArray()[0].str);
assert.isnull(c.aggregate({$project:{str:{$concat: [undefined] }}}).toArray()[0].str);
assert.isnull(c.aggregate({$project:{str:{$concat: ["$x", "$missing", "$y"] }}}).toArray()[0].str);
assert.isnull(c.aggregate({$project:{str:{$concat: ["$x", null, "$y"] }}}).toArray()[0].str);
assert.isnull(c.aggregate({$project:{str:{$concat: ["$x", undefined, "$y"] }}}).toArray()[0].str);
// assert fail for all other types
assertErrorCode(c, {$project:{str:{$concat: [MinKey]}}}, 16702);
assertErrorCode(c, {$project:{str:{$concat: [1]}}}, 16702);
assertErrorCode(c, {$project:{str:{$concat: [NumberInt(1)]}}}, 16702);
assertErrorCode(c, {$project:{str:{$concat: [NumberLong(1)]}}}, 16702);
assertErrorCode(c, {$project:{str:{$concat: [true]}}}, 16702);
assertErrorCode(c, {$project:{str:{$concat: [function(){}]}}}, 16702);
assertErrorCode(c, {$project:{str:{$concat: [{}]}}}, 16702);
assertErrorCode(c, {$project:{str:{$concat: [[]]}}}, 16702);
assertErrorCode(c, {$project:{str:{$concat: [new Timestamp(0,0)]}}}, 16702);
assertErrorCode(c, {$project:{str:{$concat: [new Date(0)]}}}, 16702);
assertErrorCode(c, {$project:{str:{$concat: [new BinData(0,"")]}}}, 16702);
assertErrorCode(c, {$project:{str:{$concat: [/asdf/]}}}, 16702);
assertErrorCode(c, {$project:{str:{$concat: [MaxKey]}}}, 16702);
assertErrorCode(c, {$project:{str:{$concat: [new ObjectId()]}}}, 16702);