does mongodb have the properties such as trigger and procedure in a relational database?

前端 未结 2 895
無奈伤痛
無奈伤痛 2021-01-04 22:56

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

2条回答
  •  盖世英雄少女心
    2021-01-04 23:18

    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?

    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.

提交回复
热议问题