trigger in mongodb

1,894 views
Skip to first unread message

ArKadia ArKadia

unread,
Jun 20, 2013, 8:14:53 AM6/20/13
to mongod...@googlegroups.com
Hello,

We need to do special task everytime a record is updated / deleted / added in the database.
as their is various kind of client that connect to the database, theses tasks must be done inside
the database engine itself to be sure that the integrity of the data will be never lost.
this is done normally via "trigger"

how to do so in mongoDB ?

thanks by advance

Asya Kamsky

unread,
Jun 21, 2013, 12:11:30 AM6/21/13
to mongod...@googlegroups.com
There are no triggers in MongoDB - this would have to be handled by the application layer.
If you can't control what clients do when they connect to the database you might consider not allowing any direct database access and instead provide an API layer on top of the database that the clients would be required to go through.

ArKadia ArKadia

unread,
Jun 21, 2013, 8:16:22 AM6/21/13
to mongod...@googlegroups.com
| If you can't control what clients do when they connect to the database you might consider not allowing any direct database access and instead provide an API layer on top of the database that the clients would be required to go through.

this is very painfull developpement :(

Trigger is an important (even vital?) features in any database system ! 
why their is not yet a support of it? is this at least planned in futur release ?

i even see people working on the log to simulate trigger ... it's sound crazy !

Sam Millman

unread,
Jun 21, 2013, 8:44:43 AM6/21/13
to mongod...@googlegroups.com
Not really, triggers are considered by many (even SQL contributors) to be overkill and micro-optimisation and also not very good in distributed envos (which MongoDB is kinda supposed to be good at).

The log version is actually a pub/sub not a trigger, they are two different things. Yes triggers exist in the JIRA: https://jira.mongodb.org/browse/SERVER-124


--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

andy

unread,
Jun 21, 2013, 10:45:34 AM6/21/13
to mongod...@googlegroups.com
We sort of want something similar, this blog post was helpful: http://danielweberonline.wordpress.com/2012/05/14/creating-triggers-for-mongodb/

Watching the oplog isn't too bad/hard (there is a node module called mongo-watch that helps, too). For limited purposes this is good enough for us.

Asya Kamsky

unread,
Jun 22, 2013, 1:51:29 AM6/22/13
to mongod...@googlegroups.com
It is the nature of every tool and piece of software that you choose for your stack that they give you some things for free
and expect you to do the work to implement other things that they don't give you.

We will probably disagree about how vital triggers are - I have worked with over half a dozen different databases in
my career and I honestly cannot remember *ever* making use of any triggers.  In fact most major RDBMSs were 
successfully used for many years before they added support for triggers.

We probably also disagree whether it is even appropriate to inject code that's opaque to the application in an
architecture in which the application is determining the role of the data store rather than database being king.

Asya

archana lohe

unread,
Aug 23, 2016, 1:54:39 PM8/23/16
to mongodb-user
Please let me know how we can have triggers in MongoDb. I have seen the example managing through the application. But I dont need to manage through application. I want to implement in the database for the collection.

John Murphy

unread,
Aug 29, 2016, 5:08:21 PM8/29/16
to mongodb-user

Hi Archana,

As previously mentioned by Asya there is currently no support for triggers in MongoDB.

The only solution at present is to implement such functionality within your application code.

Please note that we have feature request SERVER-124 that is currently tracking this. Feel free to vote and/or add any requirements you may have.

Regards,
John Murphy

Tim Hawkins

unread,
Aug 29, 2016, 5:17:22 PM8/29/16
to mongodb-user

Another possiblity is to create an oplog listener that handles the trigger actions. The oplog contains events for all changes to the database, and is used to implement replication in replica sets.

Check this out for ideas

https://github.com/benjamine/mongo-listener

Note: this is not my project, nor have i used it, but i have used/built something simular in the past.


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/

---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/901e7180-2929-437f-8028-6c791780cb06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages