-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
-
ALL
Observed behavior:
An expression $gt:[ '$a', 1 ] is optimized to a proper field path.
An expression $gt:[ 1, '$a' ] is converted to $lte:[ '$a', 1 ] (wrong, should be $lt:[ '$a', 1 ]) and optimized to a field path.
The other comparison operators are similarly affected.
Test
c = db.c; c.drop(); c.save( { a:1 } ); result = c.aggregate( { $project:{ _id:0, x:{ $gt:[ '$a', 1 ] }, y:{ $gt:[ 1, '$a' ] } } } ); printjson( result ); assert.eq( { x:false, y:false }, result.result[ 0 ] );
Probably just need to fix this configuration array.
static const CmpLookup cmpLookup[7] = { /* -1 0 1 reverse name */ /* EQ */ { { false, true, false }, Expression::EQ, "$eq" }, /* NE */ { { true, false, true }, Expression::NE, "$ne" }, /* GT */ { { false, false, true }, Expression::LTE, "$gt" }, /* GTE */ { { false, true, true }, Expression::LT, "$gte" }, /* LT */ { { true, false, false }, Expression::GTE, "$lt" }, /* LTE */ { { true, true, false }, Expression::GT, "$lte" }, /* CMP */ { { false, false, false }, Expression::CMP, "$cmp" }, };