MongoDB中的触发器(或类似的东西)? [英] Triggers (or something similar) in MongoDB?

查看:881
本文介绍了MongoDB中的触发器(或类似的东西)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个MongoDB,并且我正在其中存储数据。

Supposed I have a MongoDB, and I am storing data in it.

在插入,更新或删除数据时,MongoDB是否有可能触发?我知道有可拖动的游标,但它们仅适用于加盖的集合。

Is there any possibility to get triggered by MongoDB when data is inserted, updated or deleted? I know that there are tailable cursors, but they only work with capped collections.

还有其他内容吗?

基本上,我可以听的JavaScript API中是否存在某种事件?

Basically, is there some kind of "event" in the JavaScript API I could listen to?

推荐答案

MongoDB没有概念触发,而是推迟您使用自己的API来处理通常与SQL数据库触发器关联的任务。通常的前提是,通过更改架构设计方法以将嵌入的列表和文档包含在您要处理的文档中,可以最好地完成更新相关集合和其他此类事情的典型任务。

MongoDB does not have a concept of "triggers" and instead defers to you to work your own API to handle the tasks you typically associate with SQL Database triggers. The general premise is that the typical tasks of updating related collections and other such things are best handled by changing your schema design approach to include embedded lists and documents within the documents you are dealing with.

除了设计偏好之外,您还可以从程序的角度将触发逻辑包装到自己的API中,并控制这些功能。

Beyond that the design preference is that you wrap your "trigger" logic into your own API from the program's point of view and give that control of such functions.

如果您确实需要挂接到每个更新/插入/删除中,则可以查看跟踪 oplog 是一个特殊的加盖集合,其中包含MongoDB上所有来源处理的所有操作。

In the event that you really need to hook into every update/insert/delete you can look at tracking the oplog which is a special capped collection containing all operations from all sources processing on your MongoDB.

这篇关于MongoDB中的触发器(或类似的东西)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆