4 ms·
The downvoting is because you can have tables with single jsonb columns without schemas - call them "collections" and pretty much end up with a faster mongo up
by inglor 9y ago
The downvoting is because you can have tables with single jsonb columns without schemas - call them "collections" and pretty much end up with a faster mongo up to having to fiddle a bit more with replication/sharding.
No one is making you enforce schemas with PostgreSQL if you work this way.
As for enforcements - there are things that are _impossible_ to enforce at an application level for atomicity reasons - for example - if you have a `users` table and you can't have duplicate email addresses - you'd need the operation "check if a user with the said email exists, if it does - return it, if it doesn't create it and return it" - PostgreSQL can do this easily, which prevents duplicate entries - Mongo - not so easily (see the "two phase commit" docs for how to simulate transactions).
- 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.
- orless 9y ago> check if a user with the said email exists, if it does - return it, if it doesn't create it and return it" ... Mongo - not so easily Can't you easily do it with upsert in Mongo?
- edoceo 9y agoYep. Put an unique index on the collection too.
- petergeoghegan 9y agoI'm not sure that it's that simple in practice. MongoDB may fail to provide the same guarantees that Postgres UPSERT does, if not in theory then at least in practice. In other words, it seems like retrying within client code is necessary when the Wired Tiger storage engine happens to be in use: https://stackoverflow.com/questions/29305405/mongodb-impossible-e11000-duplicate-key-error-dup-key-when-upserting https://stackoverflow.com/questions/29305405/mongodb-impossi...