英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论