MongoTriggers

class mongotriggers.mongotriggers.MongoTrigger(conn, since=None)[source]

Bases: object

tail_oplog()[source]

Listens to oplog and fire the registered callbacks

stop_tail()[source]

Stops listening to the oplog, no callbacks after calling this

register_op_trigger(func, db_name=None, collection_name=None)[source]

Watches the specified database and collections for any changes

Parameters:
  • func (callback) – function to be invoked when any operation occurs
  • db_name (str) – name of Mongo database to watch for changes
  • collection_name (str) – name of Mongo collection to watch for changes
register_insert_trigger(func, db_name=None, collection_name=None)[source]

Adds an insert callback to the specified namespace

Parameters:
  • func (callback) – callback to execute when an insert operation occur
  • db_name (str) – name of Mongo database to watch for changes
  • collection_name (str) – name of Mongo collection to watch for changes
register_update_trigger(func, db_name=None, collection_name=None)[source]

Adds ann update callback to the specified namespace

Parameters:
  • func (callback) – callback to execute when an update operation occur
  • db_name (str) – name of Mongo database to watch for changes
  • collection_name (str) – name of Mongo collection to watch for changes
register_delete_trigger(func, db_name=None, collection_name=None)[source]

Adds a delete callback to the specified namespace

Parameters:
  • func (callback) – callback to execute when a delete operation occur
  • db_name (str) – name of Mongo database to watch for changes
  • collection_name (str) – name of Mongo collection to watch for changes
unregister_op_trigger(func, db_name=None, collection_name=None)[source]

Removes all callbacks from the specified namespace

Parameters:
  • func (callback) – callback to disable when any operation occur
  • db_name (str) – name of Mongo database to watch for changes
  • collection_name (str) – name of Mongo collection to watch for changes
unregister_insert_trigger(func, db_name=None, collection_name=None)[source]

Removes an insert callback from the specified namespace

Parameters:
  • func (callback) – callback to disable when an insert operation occur
  • db_name (str) – name of Mongo database to watch for changes
  • collection_name (str) – name of Mongo collection to watch for changes
unregister_update_trigger(func, db_name=None, collection_name=None)[source]

Removes an update callback from the specified namespace

Parameters:
  • func (callback) – callback to disable when an insert operation occur
  • db_name (str) – name of Mongo database to watch for changes
  • collection_name (str) – name of Mongo collection to watch for changes
unregister_delete_trigger(func, db_name=None, collection_name=None)[source]

Removes a delete callback from the specified namespace

Parameters:
  • func (callback) – callback to disable when an insert operation occur
  • db_name (str) – name of Mongo database to watch for changes
  • collection_name (str) – name of Mongo collection to watch for changes