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

Wrong input gets validated if converted with Int32, Long or Double

    • 3
    • 1
    • Not Needed
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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.

            Assignee:
            aditi.khare@mongodb.com Aditi Khare
            Reporter:
            sorin.gfs@protonmail.com Sorin GFS
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: