4 ms·
> 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 w
by 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...