Any downsides to validating directly against a DB schema?

fuzzybabybunny

Moderator<br>Digital & Video Cameras
Moderator
Jan 2, 2006
10,455
35
91
I'm running MongoDB (because I'm using Meteor and it only supports Mongo). Mongo is schema-less, but there are packages that enable me to add a schema to it.

There are also packages that can utilize the schema itself as the standard to validate any data entries against.

So based on this, are there any downsides to using the schema itself on the server for validation? To me it seems like it would be the fastest, most direct and secure way of validating...
 

ForumMaster

Diamond Member
Feb 24, 2005
7,797
1
0
Isn't that kind of contradictory when using such a solution such as Mongo? Mongo isn't an RDBMS. it's a json store. you store documents inside. I would think that any ORM that offers validation would hamper performance significantly.
 

fuzzybabybunny

Moderator<br>Digital & Video Cameras
Moderator
Jan 2, 2006
10,455
35
91
Isn't that kind of contradictory when using such a solution such as Mongo? Mongo isn't an RDBMS. it's a json store. you store documents inside. I would think that any ORM that offers validation would hamper performance significantly.

I think that for my humble purposes imposing a schema isn't going to be that big of a performance hit.

I'm using it more as a way to validate my forms and make sure I get correct data.

There is a package for Meteor that allows me to, for instance, on my schema set a key in my database as required and which has an integer value. On the front end I can then check for the existence of this entry and for the proper type, all in the form itself and according to the schema and only the schema, thus doing a client-side and server-side validation all in one line of code and from one single "source" of validations.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,284
3,905
75
Last edited:

Cerb

Elite Member
Aug 26, 2000
17,484
33
86
Just using Mongo is a big performance hit, before you add a schema on top of it. Why not use a real RDBMS like MariaDB? Are you doing some stuff that's actually better done in Mongo?
Using something that uses Mongo only, and thus using Mongo. Though, MySQL would be terrible for what the OP proposed, as check constraints are ignored (PostgreSQL FTW: fewer and less complex triggers).

As for validation, sending data to the DB should be the last step you do. Edit: For serious discussion, see https://en.wikipedia.org/wiki/SQL_injection
And even then, parameterize everything, everywhere you can.

If you have transaction safety, which is iffy on Mongo (I've only got docs and howtos, as I've never been in a situation where Mongo looked like anything but a way to increase the hours I would need to get anything done), then it can be handy. Without that, though, you'll likely have to make faux-transactions client-side (from Mongo's PoV), at which point it would likely be easier to check correctness well before commit attempts. Even with a solid DB, checking against the DB by trying to write it is going to cause CPU/disk spikes that an be avoided by not doing it.

If you need transaction-like behavior, you should probably add time-stamped metadata, like a value for, "form X was made on Y," and, "form X passed type/relationship/value checks on Z," so that you at least don't have unknown incorrect/orphan data at any point (a DB should only store truths, so if you scrub for them, data not matched with the full set of that metadata might not be true, and should thus be repaired or discarded).

If you're not storing prepared data, already checked for correctness and form, a basic K/V document store is not likely a good back-end, unless the data itself is largely of little importance.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |