diff options
author | Justin Seyster <justin.seyster@mongodb.com> | 2019-12-13 01:35:54 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-12-13 01:35:54 +0000 |
commit | 3a62fec23a50653994e01d1b1725d80a10fc208d (patch) | |
tree | 6eda6709522577d39a5d82a3afe25c7feb252e70 /src/mongo/db/pipeline/expression.cpp | |
parent | 07ba9da4013e908e7a9e37c4a7f482eddd9c3edc (diff) | |
download | mongo-3a62fec23a50653994e01d1b1725d80a10fc208d.tar.gz |
SERVER-43669 Serialize "sortKey" as BSONArray
Diffstat (limited to 'src/mongo/db/pipeline/expression.cpp')
-rw-r--r-- | src/mongo/db/pipeline/expression.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp index e07b2d950b5..aba6a767663 100644 --- a/src/mongo/db/pipeline/expression.cpp +++ b/src/mongo/db/pipeline/expression.cpp @@ -2700,10 +2700,24 @@ Value ExpressionMeta::evaluate(const Document& root, Variables* variables) const case MetaType::kIndexKey: return metadata.hasIndexKey() ? Value(metadata.getIndexKey()) : Value(); case MetaType::kSortKey: - return metadata.hasSortKey() - ? Value(DocumentMetadataFields::serializeSortKey(metadata.isSingleElementKey(), - metadata.getSortKey())) - : Value(); + if (metadata.hasSortKey()) { + switch (getExpressionContext()->sortKeyFormat) { + case SortKeyFormat::k42ChangeStreamSortKey: + invariant(metadata.isSingleElementKey()); + return Value(metadata.getSortKey()); + case SortKeyFormat::k42SortKey: + return Value(DocumentMetadataFields::serializeSortKeyAsObject( + metadata.isSingleElementKey(), metadata.getSortKey())); + case SortKeyFormat::k44SortKey: + return Value(DocumentMetadataFields::serializeSortKeyAsArray( + metadata.isSingleElementKey(), metadata.getSortKey())); + break; + default: + MONGO_UNREACHABLE; + } + } else { + return Value(); + } default: MONGO_UNREACHABLE; } |