Mongodb 原子模式规划

Mongodb atomic schema-planning

我的程序有用户和组。 用例:用户拥有可以给予群组的积分。

我不想丢失任何学分。

类似 RDBMS 模式的问题是 Mongo 的原子性是文档级的。我减少用户的积分,然后增加组的积分。如果应用程序在两者之间崩溃,则发送的积分将丢失。 (如果我替换这两个动作,信用可以出现而不会从用户那里撤回。)

一种解决方案可能是使用称为事务的集合。然后可以从用户的信用减去用户的发送信用来计算用户的信用。该组的信用可以计算为已发送信用的总和。问题是如果数据库增长,总和将需要一段时间。

你能给我任何可接受的、可扩展的和强大的 NoSQL 解决方案吗? (我知道这在 RDBMS 中真的很容易)

MongoDB

中的两阶段提交

您可以使用两阶段提交方法执行多文档更新或多文档事务。

Using two-phase commit ensures that data is consistent and, in case of an error, the state that preceded the transaction is recoverable. During the procedure, however, documents can represent pending data and states.

有关两阶段提交的更多详细信息,您可以参考文档here

NOTE
Because only single-document operations are atomic with MongoDB, two-phase commits can only offer transaction-like semantics. It is possible for applications to return intermediate data at intermediate points during the two-phase commit or rollback.