diff options
author | Eliot Horowitz <eliot@10gen.com> | 2015-03-11 17:45:49 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2015-03-11 17:46:44 -0400 |
commit | f4d17dd81431f9724006c0837ccac44068971b1d (patch) | |
tree | 729b7d2035cb937a6bcfcf93c8e0730230a0b003 /src/mongo/db/pipeline | |
parent | f931ac5fa8d69d1b3e08267cd47ba14e5b3b30e2 (diff) | |
download | mongo-f4d17dd81431f9724006c0837ccac44068971b1d.tar.gz |
SERVER-8088: $unwind of scalar should return 1 doc with scalar
Diffstat (limited to 'src/mongo/db/pipeline')
-rw-r--r-- | src/mongo/db/pipeline/document_source_unwind.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/mongo/db/pipeline/document_source_unwind.cpp b/src/mongo/db/pipeline/document_source_unwind.cpp index 11c8d0880ec..2caf7f95c64 100644 --- a/src/mongo/db/pipeline/document_source_unwind.cpp +++ b/src/mongo/db/pipeline/document_source_unwind.cpp @@ -87,17 +87,11 @@ 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() || _index == _inputArray.getArrayLength()) + if (_inputArray.missing()) return boost::none; // If needed, this will automatically clone all the documents along the @@ -107,7 +101,17 @@ 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). - _output.setNestedField(_unwindPathFieldIndexes, _inputArray[_index]); + 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); + } _index++; return _output.peek(); } |