Details
-
Improvement
-
Resolution: Done
-
Major - P3
-
None
-
None
Description
Javascript treats empty strings and NaN as false, but Value::coerceToBool treats them as true.
Test
c = db.c;
|
c.drop();
|
|
|
// Save some values.
|
[
|
1,
|
0,
|
true,
|
false,
|
{},
|
[],
|
null,
|
'',
|
0/0
|
].forEach( function( x ) { c.save( { a:x } ); } );
|
|
|
// Return each value and its boolean coerced value.
|
result = c.aggregate( { $project: { a:'$a', bool:{ $and:[ '$a' ] } } } ).result;
|
for( i in result ) {
|
r = result[ i ];
|
// Find the boolean coerced value in javascript and check that it matches the value from
|
// the server.
|
expectedBool = !!r.a;
|
assert.eq( expectedBool, r.bool, 'Expected ' + expectedBool + ' for (' + r.a + ').' );
|
}
|
|
|
Observed behavior:
{ $and:[ '' ] } evaluates to true.
Expected behavior:
evaluates to false.
Attachments
Issue Links
- is related to
-
SERVER-6203 Aggregation operators should have well defined implicit type coercion behavior.
-
- Backlog
-