diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-03-11 17:29:05 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-03-11 17:29:05 -0400 |
commit | 5ad411b38b020b209218017448426e9dc72382b5 (patch) | |
tree | fd265bc5b85dfb1b76978e469534c374700c4365 | |
parent | ceb58fee5495ce2b45f6aaba7aa3da76b9cdf8d9 (diff) | |
download | mongo-5ad411b38b020b209218017448426e9dc72382b5.tar.gz |
Revert "SERVER-8008: $unwind of scalar should return 1 doc with scalar"
This reverts commit 25feddadeef43fb0668350b40282fcdfbb1f2296.
-rw-r--r-- | jstests/aggregation/unwind.js | 13 | ||||
-rw-r--r-- | src/mongo/db/pipeline/document_source_unwind.cpp | 20 |
2 files changed, 8 insertions, 25 deletions
diff --git a/jstests/aggregation/unwind.js b/jstests/aggregation/unwind.js deleted file mode 100644 index 5271317fa3e..00000000000 --- a/jstests/aggregation/unwind.js +++ /dev/null @@ -1,13 +0,0 @@ -t = db.agg_unwind; -t.drop(); - -t.insert( {_id : 1 } ); -t.insert( {_id : 2, x : null } ); -t.insert( {_id : 3, x : [] } ); -t.insert( {_id : 4, x : [1, 2] } ); -t.insert( {_id : 5, x : [3] } ); -t.insert( {_id : 6, x : 4 } ); - -var res = t.aggregate( [ { $unwind : "$x" }, { $sort : { _id : 1 } } ] ).toArray(); -assert.eq(4, res.length); -assert.eq([1,2,3,4],res.map(function(z){ return z.x; })); diff --git a/src/mongo/db/pipeline/document_source_unwind.cpp b/src/mongo/db/pipeline/document_source_unwind.cpp index 4aa33633ca8..11c8d0880ec 100644 --- a/src/mongo/db/pipeline/document_source_unwind.cpp +++ b/src/mongo/db/pipeline/document_source_unwind.cpp @@ -87,11 +87,17 @@ namespace mongo { return; } + // The target field must be an array to unwind. + uassert(15978, str::stream() << "Value at end of $unwind field path '" + << _unwindPath.getPath(true) << "' must be an Array, but is a " + << typeName(pathValue.getType()), + pathValue.getType() == Array); + _inputArray = pathValue; } boost::optional<Document> DocumentSourceUnwind::Unwinder::getNext() { - if (_inputArray.missing()) + if (_inputArray.missing() || _index == _inputArray.getArrayLength()) return boost::none; // If needed, this will automatically clone all the documents along the @@ -101,17 +107,7 @@ namespace mongo { // along the path leading to that will be replaced in order not to share // that change with any other clones (or the original). - if (_inputArray.getType() == Array) { - if (_index == _inputArray.getArrayLength()) - return boost::none; - _output.setNestedField(_unwindPathFieldIndexes, _inputArray[_index]); - } - else if (_index > 0) { - return boost::none; - } - else { - _output.setNestedField(_unwindPathFieldIndexes, _inputArray); - } + _output.setNestedField(_unwindPathFieldIndexes, _inputArray[_index]); _index++; return _output.peek(); } |