Coder Social home page Coder Social logo

drorasaf / mongotriggers Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 1.0 47 KB

Allows mongodb trigger mechanism similar to the RDBM trigger mechanism

License: Other

Python 100.00%
python mongodb-replica-set trigger listener mongodb mongodb-database pymongo oplog-tailing

mongotriggers's Introduction

MongoTriggers

image

image

image

image

Documentation Status

What is this?

mongodb-triggers is a light-weight library to allow real live changes notification. This is similar to triggers in SQL. This capability can be found both in Java and JavaScript(MeteorJS)

What is it good for?

Modern applications have become near real-time response and updates, this leads to the requirement that any changes done in the data to be propagated up to the top level of the application as soon as possible.

In order to allow this to happen, any changes in the databases must be notified, similar project that use this method is https://github.com/meteor/meteor.

More Documentation can be found at http://mongotriggers.readthedocs.io

Installation

Installer is available on PyPI. You can install it through pip:

$ pip install mongotriggers

Why should I use it?

The best functionality is the one that another one is maintaining for you, as well as 100% code coverage. This package follows best practices as published by MongoDB: - https://www.mongodb.com/blog/post/tailing-mongodb-oplog-sharded-clusters - https://www.mongodb.com/blog/post/pitfalls-and-workarounds-for-tailing-the-oplog-on-a-mongodb-sharded-cluster

How to use?

Let's assume the system in development is a financial one, and every deletion in the database is extremely important, so we would like to notified for each deletion.

from mongotriggers import MongoTrigger
from pymongo import MongoClient

def notify_manager(op_document):
    print ('wake up! someone is adding me money')

client = MongoClient(host='localhost', port=27017)
triggers = MongoTrigger(client)
triggers.register_op_trigger(notify_manager, 'my_account', 'my_transactions')

triggers.tail_oplog()
client['my_account']['my_transactions'].insert_one({"balance": 1000})
triggers.stop_tail()

Keep in mind that it is meant to run in a defered context in order to run endlessly until it is cancelled.

Testing

In order to develop, the additional requirements are:

  • pytest
  • pytest-cov
  • tox

All packages can be installed using pip. The easiest way to run the tests is to run tox.

mongotriggers's People

Contributors

drorasaf avatar hotcockmiami avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

hotcockmiami

mongotriggers's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.