-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: bson-4.5.2
Env: node 14, latest MongoDB, latest MongoDB node driver.
Validation schema:
{ "validator": { "$jsonSchema": { "bsonType": "object", "properties": { "int": { "bsonType": "int" } , "long": { "bsonType": "long" } , "double": { "bsonType": "double" } , "decimal": { "bsonType": "decimal" } } } }, "validationLevel": "moderate", "validationAction": "error" }
Operation:
const foo= 'foo'; const data = { int: new Int32(foo), long: new Long(foo), double: new Double(foo), decimal: new Decimal128(foo), } ; await db.collection.insertOne(data);
Result: inserted in db:
int = 0; // as valid Int32 bsonType long = 0; // as valid Long bsonType double = NaN; // as valid Double bsonType // decimal throws error: foo not a valid Decimal128 string TypeError
All these 4 conversion functions are wrong, the first 3 returns the valid data type to the wrong input, and Decimal128 throws an error ... when in fact all 4 should return the wrong input so that it can then be invalidated by the validation rules.
If anything we enter is converted into a valid record... the validation is useless.
There are no Sub-Tasks for this issue.