Re:MongoDB 3.4.0-rc3
by disgusting_guy on Wednesday February 08, 2017 @05:32AM
(#13597248)
You describe it like it is simple but that is ridiculous number of steps to simply check your data was actually written to the database.
>that's as reliable as it gets when inserting into any database including SQL
The difference being in a SQL database you call commit and all this happens for you automatically
You check the result with getLastError which, as you described, can be used to ensure a majority agrees with the write. But you normally don't use getLastError that way. Because a majority might not even be concerned with that particular write. They are, after all, shards. Instead you check if primary got the write. If primary disconnects while you are checking, you catch the exception and try checking until a new primary is decided. And if your check result is not ok, you try inserting again. That's as reliable as it gets when inserting to any database including SQL databases that support transactions.