Mongodb触发函数调用有内置方法吗? [英] Is there a built-in way for Mongodb trigger function calls?

查看:126
本文介绍了Mongodb触发函数调用有内置方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用MongoDB,例如它像带有单元格的电子表格的数据库版本:总和计算中涉及的数据组,或从文档到下一个的连续总计清单。
(当然,可以预期其他计算类型)

I want to use MongoDB such as it is like a database version of a spreadsheet with cells: groups of data involved in sum calculations, or inventory with a running total from a document to the next. (of course, other calculation types can be expected)

这意味着每次我们获得插入/编辑/删除
时都需要运行重新计算可能包含在进一步计算中的内容,因此,结果本身可能是另一次重新计算的触发因素。

It means everytime we get an insert/edit/delete it is needed to run the re-calculation for something that is maybe involved in a further calculation thus, the result might be itself a trigger for another re-calculation.

是否有内置的测试插入/编辑/删除的方法,将调用重新计算方法? (如果结果会影响下一次重新计算,则可能是级联)

Is there a built-in way to test insert/edit/delete that would call re-calculation methods? (maybe in cascade if a result has an effect on a next re-calculation)

我想,这样的触发器将调用特定的函数并为其提供:属性名称(插入/编辑/删除),集合,文档ID,操作类型以及以前和新的值)

I suppose, such trigger would call a specific function and would supply it with: Attribute name (inserted/edited/deleted), Collection, Document ID, operation type and maybe previous and new values)

(属性和文档级别触发器)

(attribute and document level triggers)

我想,另一种查看方式是具有重复读取功能,不断读取oplog文件并采取相应措施。

I suppose, another way to see it is have a recurring function constantly reading oplog files and act accordingly.

谢谢,
Marc

Thanks, Marc

推荐答案

从当前版本(3.0.2)开始,MongoDB不支持触发器,更不用说级联触发器了。带有依赖于其他字段值的字段的文档也是您必须在应用程序层上实现的。

As of the current version (3.0.2), MongoDB has no support for triggers, let alone cascading triggers. Documents with fields which depend on the values of other fields are also something you have to implement on the application layer.

作为数据库,几乎所有应用程序逻辑都留给了数据库。应用程序,这样的功能实际上不在其设计范围之内。

As a database which leaves almost all the application logic to the application, functionality like this isn't really in the scope of its design.

当您真的想为该项目使用MongoDB时(IMO似乎并非如此)。完全适合该项目),则您必须自己实现所有这些功能。

When you really want to use MongoDB for this project (IMO it doesn't seem to be the right tool for this project at all), you will have to implement all of this yourself.

您可以在应用程序上实现此功能,但是当字段依赖关系很长时,如果您需要一个接一个地检索并保存每个文档,这可能会变得很难看。或者,您可以尝试修改MongoDB本身以添加对此的支持。 MongoDB是开源的,因此您可以随意破解它。使用免费版本时,请记住阅读 AGPL 的许可条款当您让别人拥有的系统连接到修改后的MongoDB时,这是很重要的。

You could either implement this on the application, but this could turn ugly when you have long chains of field dependencies as you need to retrieve and save every document one after another. Or you could try to modify MongoDB itself to add support for this. MongoDB is open source, so you can hack it all you want. When you use the free version, remember to read the license terms of the AGPL which are relevant when you let systems owned by someone else connect to your modified MongoDB.

这篇关于Mongodb触发函数调用有内置方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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