summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_unwind.cpp
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-03-11 17:29:05 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-03-11 17:29:05 -0400
commit5ad411b38b020b209218017448426e9dc72382b5 (patch)
treefd265bc5b85dfb1b76978e469534c374700c4365 /src/mongo/db/pipeline/document_source_unwind.cpp
parentceb58fee5495ce2b45f6aaba7aa3da76b9cdf8d9 (diff)
downloadmongo-5ad411b38b020b209218017448426e9dc72382b5.tar.gz
Revert "SERVER-8008: $unwind of scalar should return 1 doc with scalar"
This reverts commit 25feddadeef43fb0668350b40282fcdfbb1f2296.
Diffstat (limited to 'src/mongo/db/pipeline/document_source_unwind.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_unwind.cpp20
1 files changed, 8 insertions, 12 deletions
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();
}