5

I am looking at using MongoDB for an app. I am rather new to MongoDB. I need to track the changes users makes to the system, what was added/changed and when. The oplog appears to contain all the data I need and it seemed to me that persisting a copy of the oplog to a separate uncapped collection would give me all the history I need. It would not need to be quickly retrievable or immediately available.

Is there a problem with this approach? Can anyone suggest a best way to store this data?

4

1 回答 1

3

这种方法的问题在于它的级别极低。将这些信息恢复到从应用程序的角度来看有意义的程度将是非常烦人的。

例如,假设您要更改用户的名称。您使用$set还是替换用户对象?从应用程序的角度来看,没关系,但 oplog 看起来会完全不同。此外,如果您使用替换,则 oplog 中包含的信息将不仅包含更改,还包含新状态。这意味着了解真正发生的事情的唯一方法是对所有操作执行完整的回放(所以你有旧的和新的状态)。

此外,oplog 不包含有关哪个用户执行了哪个操作的任何信息,除非您将数据库用户用作应用程序用户,我强烈建议您不要这样做。

在我看来,这应该由应用程序处理。例如,您可以使用工作单元模式,但不是在客户端上间歇性地使用它,您可能希望将工作单元(或它的某种表示形式)实际序列化到数据库中。我很确定这种模式有一个名字,我现在不记得了。

于 2013-11-04T21:46:44.087 回答