Rectangle 27 4

I think that while not elegant, the oplog could be partially used for this purpose: it logs all the writes - but not the reads...

MongoDB logging all queries - Stack Overflow

mongodb logging
Rectangle 27 12

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: 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. 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.

does mongodb have the properties such as trigger and procedure in a re...

mongodb triggers procedure
Rectangle 27 1

Looks like there may be a method for achieving this detailed within the following thread: How to listen to changes to a MongoDB collection?

That answer requires making the collection a capped collection, which comes with some significant limitations on the capability of the collection. Another solution is to use tailable cursors with the oplog (which is a capped collection).

mongodb - How to observe a (mongo) collection in Ruby? - Stack Overflo...

ruby mongodb mongoid observer-pattern observers
Rectangle 27 2

You are talking about 'triggering'. But unfortunately "MongoDB does not support triggers".

For solving your issue simply create another collection and store the log information into that collection.

node.js - How to enable auditing and log all CRUD operations in MongoD...

node.js mongodb
Rectangle 27 92

What you are thinking of sounds a lot like triggers. MongoDB does not have any support for triggers, however some people have "rolled their own" using some tricks. The key here is the oplog.

When you run MongoDB in a Replica Set, all of the MongoDB actions are logged to an operations log (known as the oplog). The oplog is basically just a running list of the modifications made to the data. Replicas Sets function by listening to changes on this oplog and then applying the changes locally.

I cannot detail the whole process here, it is several pages of documentation, but the tools you need are available.

You will also want to leverage tailable cursors. These will provide you with a way to listen for changes instead of polling for them. Note that replication uses tailable cursors, so this is a supported feature.

You can start the server with the --replSet option and it will create / populate the oplog. Even without the secondary. This is definitely the only way to "listen" to changes in the DB.

I know the question is a bit older, but take a look at

Cooooool! That's really what I want. And I found a library named 'mongo-oplog' on npm. So happy~

How to listen for changes to a MongoDB collection? - Stack Overflow