Welcome to the new MongoDB Feedback Portal!
{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.
We’ve upgraded our feedback system to better capture, track, and act on your feedback. Here’s what you need to know:
|
What problem are you trying to solve? Focus on the what and why of the need you have, not the how you'd like it solved. |
Our collection has some complex $expr rules for validating our collection. Unfortunately, $expr does not allow us to add a title or description to explain what the validation is doing, so our devs just see a giant expression with no idea what it does. |
|
What would you like to see happen? Describe the desired outcome or enhancement. |
For collection validation, allow us to add a description field within an $expr validation so that we can explain in text what purpose the validation serves |
|
Why is this important to you or your team? Explain how the request adds value or solves a business need. |
This is necessary to document our collection validation and ensure new devs understand why we have it |
What steps, if any, are you taking today to manage this problem? |
Right now, I have to manually explain to the team each piece of validation and hope they remember, or document it externally elsewhere and hope the link remains intact |
Thank you for your feedback! We understand the need for clearer context when validation fails.
While we don't currently plan to implement descriptions directly within expressions (as its primary utility seems specific to the validation use case), I can suggest several workarounds that might be helpful:
1. Combine
$jsonSchemawith$exprYou can define rules that
$jsonSchemacan handle within a$jsonSchemablock, utilizing itsdescriptionfield, and reserve$expronly for complex, cross-field logic that$jsonSchemacannot express. Combine them using a top-level$and.Example:
2. Separate
$exprRulesInstead of one
$exprwith many conditions, break it into multiple$exprclauses joined by a top-level$and. If validation fails, the error message will list only the specific$exprblocks that failed.Example
3. Techniques for Embedding Descriptions Inside
$exprWhile not perfectly elegant, you can embed descriptive text or documentation links directly into your separate
$exprclauses in a way that doesn't affect the logic but does appear in the error output'sspecifiedAsfield.Here are two ways to do this:
Option A: Using
$let(Define an unused variable to hold the description)Option B: Using
$and(Add the description string as the "truthy" element)Combining approach #2 (separate
$exprblocks) with approach #3 (embedding descriptions) gives you both isolation of the failing rule and descriptive text within the error message for that rule. We do not expect these approaches to have meaningful performance impact on your writes.Hope these will be helpful.