diff options
Diffstat (limited to 'src/mongo/db/pipeline/expression.cpp')
-rw-r--r-- | src/mongo/db/pipeline/expression.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp index d86b50c527a..f7b723798f5 100644 --- a/src/mongo/db/pipeline/expression.cpp +++ b/src/mongo/db/pipeline/expression.cpp @@ -2806,9 +2806,14 @@ Value ExpressionMeta::evaluate(const Document& root, Variables* variables) const // Be sure that a RecordId can be represented by a long long. static_assert(RecordId::kMinRepr >= std::numeric_limits<long long>::min()); static_assert(RecordId::kMaxRepr <= std::numeric_limits<long long>::max()); - return metadata.hasRecordId() - ? Value{static_cast<long long>(metadata.getRecordId().as<int64_t>())} - : Value(); + if (!metadata.hasRecordId()) { + return Value(); + } + + return metadata.getRecordId().withFormat( + [](RecordId::Null n) { return Value(); }, + [](const int64_t rid) { return Value{static_cast<long long>(rid)}; }, + [](const OID& oid) { return Value(oid); }); case MetaType::kIndexKey: return metadata.hasIndexKey() ? Value(metadata.getIndexKey()) : Value(); case MetaType::kSortKey: |