Which approach to validation is the “best”?
As it stands today the current “most common” ways to approach data validation are the following: Allow/Deny, Simple-Schema/Collection2, Astronomy and possibly MongoDB 3.2 Validation - with a question mark for the last one.
For the purposes of this conversation, best is defined as:
- Simple to understand/use
- Long-Term Support
- Using packages/codebase which is currently being well maintained.
- Offers server AND client side validation
- Custom error handling (for the user experience)
Concerns about the aforementioned approaches:
I have found this method to be confusing in the past, and I have seen other complains which seam to resonate with how I feel about allow/deny. Maybe, however, this is the best way for me to achieve what I’m trying to do - and it is at least well documented and well maintained and I believe will be supported by meteor for a long time.
Simply put, It’s questionable to me that this package is going to stick around and be maintained well. This is actually why I set out on a different way to achieve my goals in validation for this application I’m building now.
I can’t find a single tutorial on how to use this - and I highly doubt that one exists. Trying to search for something that talks about this lead me to one of those elusive google searches that turned up only 3 results. It also feels “heavy” and seams like it comes from that “I want to do things in meteor, but I love PHP too much to change” perspectives (mentioned in the actual documentation). Even though Eric Dobbertin (AKA Aldeed) said “If this package were around when I created SimpleSchema, I would have used it instead of creating SimpleSchema”.
This actually is my favorite of all of the ways, because it seams to me that the folks over at MongoDB generally know what they are doing, and I feel like a method derived from using this pattern would simply be elegant. However I can’t find a SINGLE mention of anyone actually using this in real development.
If anyone could provide an example on how to use this for validation in meteor, with bonus points in react - I would owe you a beer, or a soda, or whatever your poison is. Heck, I’d buy you dinner.
For the purpose of this conversation, I’ll also add that right now I’m building a fairly simple application. I want to do a few simple form validations in receiving data as input from users.
Specifically, I need to:
- check that a “slug” is unique within the collection so that I can use it as a reliable identifier.
- check word/character count limits.
I do need to make sure these checks happen both server and client side. I also expect this list to grow in the future and become more complicated as the application grows.
Also, note that I am using React, and React-Router on the front end of things here.
Any input on these topics is welcomed. After doing all of this research today I’m feeling kind of lost as to the best way to approach this. And if you’ve read this far - thanks for your time and attention.