Details
-
Improvement
-
Status: Closed
-
Minor - P4
-
Resolution: Duplicate
-
4.2.6
-
None
-
None
-
None
-
Triage
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.
Attachments
Issue Links
- duplicates
-
SERVER-20547 Expose the reason an operation fails document validation
-
- Closed
-