[SERVER-54817] Include number of items in the error for array length validation Created: 26/Feb/21  Updated: 29/Oct/23  Resolved: 16/Mar/21

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 4.9.0

Type: Improvement Priority: Major - P3
Reporter: Katya Kamenieva Assignee: Mihai Andrei
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Query Execution 2021-03-22
Participants:

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



 Comments   
Comment by Githook User [ 16/Mar/21 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}

Message: SERVER-54817 Include number of items in the error for array length validation
Branch: master
https://github.com/mongodb/mongo/commit/19b5bffed6b39c97b32c1dbfec6dbbd7cd7c649e

Generated at Thu Feb 08 05:34:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.