简体   繁体   English

Mongodb 更改流获取以前的值?

[英]Mongodb change streams getting previous values?

Recently I learned about change streams in mongodb and how powerful they are, but I'm in need of getting the previous values before an update.最近我了解了 mongodb 中的更改流以及它们的强大功能,但是我需要在更新之前获取以前的值。 However, I seem to have learned through some research that it's impossible to get the previous values?但是,我似乎通过一些研究了解到,不可能获得以前的值? So this got me thinking about what alternatives exist in order to retrieve those previous values?所以这让我思考存在哪些替代方案来检索那些以前的值?

What I want to achieve is a logging system such as, “Record A field has changed from {old_value} to {new_value}.”我想要实现的是一个日志系统,例如“记录 A 字段已从 {old_value} 更改为 {new_value}”。 I'm using socket.io to push these updates to a react front-end client.我正在使用 socket.io 将这些更新推送到 React 前端客户端。 The updates to records would be happening from a completely different system and not on the same blackened server where the change streams would be listening so I won't be able to query the document before updating.记录的更新将发生在一个完全不同的系统上,而不是发生在更改流正在侦听的同一个变黑的服务器上,因此我将无法在更新前查询文档。

So I started to think of a different solution…maybe I could have two databases?所以我开始想一个不同的解决方案……也许我可以有两个数据库? One contains the old records and the other the updated records but this sounds like a duplication of data.一个包含旧记录,另一个包含更新的记录,但这听起来像是重复数据。 And I can't imagine having thousands of records.我无法想象拥有数千条记录。

I need some guidance as I really don't know what the best option is?我需要一些指导,因为我真的不知道最好的选择是什么? Is there really no way you can use change streams and get the previous values?真的没有办法使用更改流并获取以前的值吗? Is it possible to somehow query the document before a change stream event?是否可以在更改流事件之前以某种方式查询文档? Thank you.谢谢你。

不知道我是怎么错过的,但解决方案是对数据进行版本控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM