diff options
author | Davis Haupt <davis.haupt@mongodb.com> | 2022-11-17 20:02:29 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-12-02 15:14:10 +0000 |
commit | 1b09fda91c50ae3f0aef49d81a9c88bbe0e7dc2d (patch) | |
tree | 461b1c330c7869ebda8672f45887af36da5a8f72 /src/mongo/db/pipeline/expression.cpp | |
parent | 4fff248e19ed3793f67907aa1860f05f80459134 (diff) | |
download | mongo-1b09fda91c50ae3f0aef49d81a9c88bbe0e7dc2d.tar.gz |
SERVER-71450 Add bitwise not to aggregation language
Diffstat (limited to 'src/mongo/db/pipeline/expression.cpp')
-rw-r--r-- | src/mongo/db/pipeline/expression.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp index 76432eceb90..c773c25073e 100644 --- a/src/mongo/db/pipeline/expression.cpp +++ b/src/mongo/db/pipeline/expression.cpp @@ -8049,6 +8049,27 @@ Value ExpressionTsIncrement::evaluate(const Document& root, Variables* variables REGISTER_STABLE_EXPRESSION(tsIncrement, ExpressionTsIncrement::parse); +/* ----------------------- ExpressionBitNot ---------------------------- */ + +Value ExpressionBitNot::evaluateNumericArg(const Value& numericArg) const { + BSONType type = numericArg.getType(); + + if (type == NumberInt) { + return Value(~numericArg.getInt()); + } else if (type == NumberLong) { + return Value(~numericArg.getLong()); + } else { + uasserted(ErrorCodes::TypeMismatch, + str::stream() << getOpName() + << " only supports int and long, not: " << typeName(type) << "."); + } +} + +REGISTER_STABLE_EXPRESSION(bitNot, ExpressionBitNot::parse); +const char* ExpressionBitNot::getOpName() const { + return "$bitNot"; +} + MONGO_INITIALIZER_GROUP(BeginExpressionRegistration, ("default"), ("EndExpressionRegistration")) MONGO_INITIALIZER_GROUP(EndExpressionRegistration, ("BeginExpressionRegistration"), ()) |