Skip to content
Stephan Bösebeck edited this page May 6, 2018 · 1 revision

Morphium is able to get push information from Mongodb when Data changes via the OplogMonitor.

Unfortunately the oplog is only available on Replicasets, so you need to be connected to one in order to use the OplogMonitor.

The oplog monitor creates a tailable Cursor on the oplog collection, so you will be informed about every write access to your data.

Here is the code:

        OplogListener lst = data -> {
            gotIt = true;
            log.info("Got data:" + Utils.toJsonString(data));
        };
        OplogMonitor olm = new OplogMonitor(morphium, ".*cached.*", true);
        olm.addListener(lst);
        olm.start();

You need to have a look at the data you get from Mongodb, the Map data contains a lot of information about what happened, some info here:

  • there is an entry called op in this map. Op is the operation being done, I means insert, U update, C command
  • depending on the op, the map looks different. on Insert, the Object that was inserted is stored with the key o in the map. It is the full document being saved. on Update the id of the Object that was updated can be read using the keys o2->_id

The new messaging uses the oplogmonitor to get informed about changes to the message queue with out polling.