3 ms·
Uniq indexes in MongoDB has been a thing since forever. You can enforce complex constrains like this in `>3.0`: db.createCollection( "contacts", {
by hartator 10y ago
Uniq 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 10y 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 10y 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.