mongodb 有关系数据库中的触发器和过程等属性吗? [英] does mongodb have the properties such as trigger and procedure in a relational database?

查看:16
本文介绍了mongodb 有关系数据库中的触发器和过程等属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所暗示的,包括 map-reduce 框架如果我想在插入记录之前触发一个事件来运行一致性检查或安全操作,我该如何使用 MongoDB 做到这一点?

as the title suggests, include out the map-reduce framework if i want to trigger an event to run a consistency check or security operations before a record is inserted, how can i do that with MongoDB?

推荐答案

MongoDB 不支持触​​发器,但人们已经围绕触发器创建了解决方案,主要使用 oplog,尽管这只会在您使用副本集运行时对您有所帮助,因为 oplog 是一个有上限的集合,它为了复制而跟踪数据更改.有关 nodejs 解决方案,请参阅:https://www.npmjs.org/package/mongo-watch 或查看较早的 SO 线程:How to listen for对 MongoDB 集合的更改?

MongoDB does not support triggers, but people have created solutions around them, mostly using the oplog, though this will only help you if you are running with replica sets, as the oplog is a capped collection that keeps track of data changes for the purposes of replication. For a nodejs solution see: https://www.npmjs.org/package/mongo-watch or see an earlier SO thread: How to listen for changes to a MongoDB collection?

如果您关心一致性,请阅读 mongoDB 中的写入问题.http://docs.mongodb.org/manual/core/write-concern/ 通过设置插入写入关注级别,从火和希望到从副本集的所有成员那里获得确认,您可以随心所欲地放松或严格.

If you are concerned with consistency, read about write concern in mongoDB. http://docs.mongodb.org/manual/core/write-concern/ You can be as relaxed or as strict as you want by setting insert write concern levels, from fire and hope to getting an acknowledgement from all members of the replica set.

因此,如果您想在插入数据之前运行一致性检查,您可能需要将该逻辑移至客户端应用程序并将写入关注级别设置为可确保一致性的级别.

So, if you want to run a consistency check before inserting data, you probably will have to move that logic to the client application and set your write concern level to a level that will ensure consistency.

这篇关于mongodb 有关系数据库中的触发器和过程等属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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