[SERVER-48646] JSON Schema validation error does not indicate invalid fields Created: 08/Jun/20  Updated: 06/Dec/22  Resolved: 08/Jun/20

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

Type: Improvement Priority: Minor - P4
Reporter: Valentin Agachi Assignee: Backlog - Triage Team
Resolution: Duplicate Votes: 3
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-20547 Expose the reason an operation fails ... Closed
Assigned Teams:
Server Triage
Participants:

 Description   

When using JSON Schema validation on a collection, the error returned by the server does not contain any information about which fields didn't match the schema.

Steps to reproduce

1. Create a collection with a JSON Schema validator:

db.createCollection('testschema', {
  validator: {
    $jsonSchema: {
      bsonType: 'object',
      properties: {
        name: { bsonType: 'string' }
      }
    }
  }
})

2. Try to insert a document which does not respect the schema:

 db.getCollection('testschema').insertOne({ name: 123 })

Actual result

 2020-06-08T17:25:29.696+0200 E QUERY [js] WriteError: Document failed validation :
 WriteError({
 "index" : 0,
 "code" : 121,
 "errmsg" : "Document failed validation",
 "op" : {
   "_id" : ObjectId("5ede5869cc2a7550ab8ab047"),
   "name" : 123
  }
})
 WriteError@src/mongo/shell/bulk_api.js:461:48
 Bulk/mergeBatchResults@src/mongo/shell/bulk_api.js:841:49
 Bulk/executeBatch@src/mongo/shell/bulk_api.js:906:13
 Bulk/this.execute@src/mongo/shell/bulk_api.js:1150:21
 DBCollection.prototype.insertOne@src/mongo/shell/crud_api.js:252:9
 @(shell):1:1

Expected result

The error should contain information about which fields failed to match the validation schema.



 Comments   
Comment by Carl Champain (Inactive) [ 08/Jun/20 ]

Hi avaly@plexapp.com,

I believe this is being worked on in SERVER-20547 so I'm going to close this ticket as a duplicate. Please let me know if this is actually a different issue.

Thanks,
Carl
 

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