触发一次查询,当记录发生更改时。

huangapple go评论56阅读模式
英文:

mongodb - triger a query once a record changes

问题

在特定字段上定义更新查询触发器是否可能?

例如,假设我有一个包含人员信息的集合,可能存在家庭关系,例如:父子关系。这意味着一个记录可以指向另一个记录(一种树结构)。

每当我更新特定字段时,我想同时更新树中的父记录(如果我更新了儿子的字段,我想触发更新并更新父记录)。

是否有可能实现这样的功能?(完全在数据库级别完成)

英文:

Is it possible to define some kind of a update query trigger on a specific field?

For example, lets say i have a collection that contain people, and might have family relations. e.g : father to son. which means one record can point to another. (some sort of a tree).

Every time i update a specific field, i would like to also update the records parents in the tree (if i update a son's field, i would like to trigger an update and update the father as well).

Is anything like that possible? (being done entirely on DB level)

答案1

得分: 1

不完全是在数据库上,但有https://www.mongodb.com/docs/manual/changeStreams/和一个方便的封装器供Atlas用户使用https://www.mongodb.com/docs/atlas/triggers/。

触发器是在数据库上发起的,执行查询的逻辑在监听器一侧 - 应用程序、组件或单独的服务。

英文:

Not entirely on a DB, but there are https://www.mongodb.com/docs/manual/changeStreams/ and a convenience wrapper for Atlas users https://www.mongodb.com/docs/atlas/triggers/.

The trigger is originated on the DB, and the logic to perform the query is on the listener side - the application, component, or a separate service.

huangapple
  • 本文由 发表于 2023年7月24日 19:07:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753863.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定