Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3661

Investigate NODE-3660 - Wrong input gets validated if converted with Int32, Long or Double

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • 2
    • Not Needed

      NODE-3660 Description
      Env: node 14, latest MongoDB, latest MongoDB node driver.

      Validation schema:

      ```json
      {
      "validator": {
      "$jsonSchema": {
      "bsonType": "object",
      "properties": {
      "int":

      { "bsonType": "int" }

      ,
      "long":

      { "bsonType": "long" }

      ,
      "double":

      { "bsonType": "double" }

      ,
      "decimal":

      { "bsonType": "decimal" }

      }
      }
      },
      "validationLevel": "moderate",
      "validationAction": "error"
      }
      ```

      Operation:

      ```js
      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:
      ```js
      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.

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            dbeng-pm-bot PM Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: