Include number of items in the error for array length validation

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Major - P3
    • 4.9.0
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Fully Compatible
    • Query Execution 2021-03-22
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      When document fails validation because the number of array elements did not match (using JSON Schema maxItems/minItems), the message doesn't return the length of the considered array. This may be not convenient for large arrays, as user has to count the items in "consideredValue" to understand if the count was off by 1 or more significantly.

      Meanwhile on violation of "maxProperties"/"minProperties" the error contains the number of properties.

      v={
         "$jsonSchema": {
             "properties": {
                 "myArray": {
                     "bsonType": "array",
                     "maxItems": 3
                 }
             },
             "maxProperties": 1
         }
      };
      
      db.createCollection("c", {validator: v});
      db.c.insert({myArray: [1,2,3,4,5], key:"value"})
      {
            "failingDocumentId": ObjectId("60391cae714cc76b719698a5"),
            "details": {
              "operatorName": "$jsonSchema",
              "schemaRulesNotSatisfied": [
                {
                  "operatorName": "properties",
                  "propertiesNotSatisfied": [
                    {
                      "propertyName": "myArray",
                      "details": [
                        {
                          "operatorName": "maxItems",
                          "specifiedAs": {
                            "maxItems": 3
                          },
                          "reason": "array did not match specified length",
                          "consideredValue": [1, 2, 3, 4, 5]
                        }
                      ]
                    }
                  ]
                },
                {
                  "operatorName": "minProperties",
                  "specifiedAs": {
                    "minProperties": 10
                  },
                  "reason": "specified number of properties was not satisfied",
                  "numberOfProperties": 3
                }
              ]
            }
          }
      

            Assignee:
            Mihai Andrei
            Reporter:
            Katya Kamenieva
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: