diff options
author | Charlie Swanson <charlie.swanson@mongodb.com> | 2015-05-28 14:36:42 -0400 |
---|---|---|
committer | Charlie Swanson <charlie.swanson@mongodb.com> | 2015-06-15 13:29:53 -0400 |
commit | 5717454bc3c50c9ac985dcb77639f2710dfda8e4 (patch) | |
tree | ecf84f9be86e8346c732d8b613ebe7270ad7b941 /jstests/aggregation | |
parent | ba6a3b8e5075f8dec1c8d3dadee6c91b7c7dc112 (diff) | |
download | mongo-5717454bc3c50c9ac985dcb77639f2710dfda8e4.tar.gz |
SERVER-14872: Aggregation expression to concatenate multiple arrays into one
Diffstat (limited to 'jstests/aggregation')
-rw-r--r-- | jstests/aggregation/bugs/server14872.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/jstests/aggregation/bugs/server14872.js b/jstests/aggregation/bugs/server14872.js new file mode 100644 index 00000000000..3be4018ac21 --- /dev/null +++ b/jstests/aggregation/bugs/server14872.js @@ -0,0 +1,39 @@ +// SERVER-14872: Aggregation expression to concatenate multiple arrays into one + +// For assertErrorCode. +load('jstests/aggregation/extras/utils.js'); + +(function() { + 'use strict'; + + var coll = db.agg_concat_arrays_expr; + coll.drop(); + + assert.writeOK(coll.insert({a: [1, 2], b: ['three'], c: [], d: [[3], 4], e: null, str: 'x'})); + + // Basic concatenation. + var pipeline = [{$project: {_id: 0, all: {$concatArrays: ['$a', '$b', '$c']}}}]; + assert.eq(coll.aggregate(pipeline).toArray(), [{all: [1, 2, 'three']}]); + + // Concatenation with nested arrays. + pipeline = [{$project: {_id: 0, all: {$concatArrays: ['$a', '$d']}}}]; + assert.eq(coll.aggregate(pipeline).toArray(), [{all: [1, 2, [3], 4]}]); + + // Concatenation with 1 argument. + pipeline = [{$project: {_id: 0, all: {$concatArrays: ['$a']}}}]; + assert.eq(coll.aggregate(pipeline).toArray(), [{all: [1, 2]}]); + + // Concatenation with no arguments. + pipeline = [{$project: {_id: 0, all: {$concatArrays: []}}}]; + assert.eq(coll.aggregate(pipeline).toArray(), [{all: []}]); + + // Any nullish inputs will result in null. + pipeline = [{$project: {_id: 0, all: {$concatArrays: ['$a', '$e']}}}]; + assert.eq(coll.aggregate(pipeline).toArray(), [{all: null}]); + pipeline = [{$project: {_id: 0, all: {$concatArrays: ['$a', '$f']}}}]; + assert.eq(coll.aggregate(pipeline).toArray(), [{all: null}]); + + // Error on any non-array, non-null inputs. + pipeline = [{$project: {_id: 0, all: {$concatArrays: ['$a', '$str']}}}]; + assertErrorCode(coll, pipeline, 28664); +}()); |