3 ms·
Database constraints are intended for use in distributed systems problems (e.g. two people create accounts with the same email, buy the last item in the store,
by garysieling 9y ago
Database constraints are intended for use in distributed systems problems (e.g. two people create accounts with the same email, buy the last item in the store, etc).
Whether you enforce password complexity in the database is a question of where your team is more comfortable working, and what the business requirements are.
- hartator 9y agoUniq indexes in MongoDB has been a thing since forever. You can enforce complex constrains like this in `>3.0`: db.createCollection( "contacts", { validator: { $or: [ { phone: { $type: "string" } }, { email: { $regex: /@mongodb\.com$/ } }, { status: { $in: [ "Unknown", "Incomplete" ] } } ] } } ) While still not having to define the rest of the schema that you don't want too. It feels more flexible.
- icebraining 9y agoMore flexible than what? You can do the same in Postgres, just use a single JSON field (which lets you store any structure) and add constraints on the JSON key(s).
- garysieling 9y agoYou can do things like this in Postgres as well - my point was that the database are designed to solve distributed systems problems, so your database of choice is a good place to solve those problems. I couldn't make a universal statement about where the constraints you're talking about should go without knowing the business rules for the application.