Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-54817

Include number of items in the error for array length validation

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 4.9.0
    • None
    • Querying
    • None
    • Fully Compatible
    • Query Execution 2021-03-22

    Description

      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
                }
              ]
            }
          }
      

      Attachments

        Activity

          People

            mihai.andrei@mongodb.com Mihai Andrei
            kateryna.kamenieva@mongodb.com Katya Kamenieva
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: