Explain why "Document failed validation"
When saving a document fails, and the error "Document failed validation" is raised, it would be incredibly useful to know in what way the document does not match the validation schema.
There's a whole meme at my company about this error and the hours we waste chasing down the various causes.
Yes I'm aware of the "application validation" argument. We do it too. But we have big documents, big collections, and frequent schema migrations; there's going to be issues. Compass does not access MongoDb though our application, so it seems like the right place to be able to know "why".
TL;DR I might get back years of my life if Compass could just tell me why documents fail validation instead of obtusely repeating "Document failed validation" as I trial and error my way to an early grave.
![](https://secure.gravatar.com/avatar/b211cfdfd161198e0372ff8d10cce5c5?size=40&default=https%3A%2F%2Fassets.uvcdn.com%2Fpkg%2Fadmin%2Ficons%2Fuser_70-6bcf9e08938533adb9bac95c3e487cb2a6d4a32f890ca6fdc82e3072e0ea0368.png)
-
Nicholas commented
At time of writing, Mongo Compass 1.35 with MongoDB 5.0.x doesn't give details as to why the document failed validation, have to use the command-line (mongosh) to get the details[1], which is important for any sufficiently advanced document. The feature described would useful! Thanks!
[1] https://www.mongodb.com/developer/products/mongodb/mongodb-5-0-schema-validation/
-
George commented
With v5 there are no reasons to not have this implemented.
-
Guillaume commented
Now that with version 5.0 the validation schema errors are returned by Mongo, can the functionality be implemented in Compass?
-
AdminMassimiliano (Admin, MongoDB) commented
I investigated this further. Looks like the server does not return the reason for the document to be invalid. The server team is working on it, targeting MongoDB 4.6: https://jira.mongodb.org/browse/SERVER-20547. Once that is available in the server's response, we will surface it in Compass.
-
AdminMassimiliano (Admin, MongoDB) commented
Thank you for the feedback. Let us see what we can do about this. If the server gives us more information back along with the error we can see how to surface it best in the UI.