Reply response filter

This filter gets (potentially) invoked for every response packet of type REPLY. Note that modern MongoDB applications tend to use MSG packets, but REPLY packets are still in use for some authentication methods, and for older apps.


JSON expression : optional - a JSON expression. If specified, the filter will be invoked only if at least one of the documents in the packet matches the expression.


The following variables will always be defined when your JavaScript executes:

  • log : the log object

  • context : contains all the variables you'll commonly use:

    • packet : the packet being filtered, which will always be a REPLY packet

    • matchPath : if the JSON expression parameter is set, then this variable will be set to a list of strings representing the path to the first match in the object. In other words, this points out the reason why this object is being filtered. This is only useful if the JSON expression contains one or more * qualifiers. Note that these are strings, and therefore may need to be converted (typically using parseInt) if they represent numbers.

    • result : the result object, used to cancel the current packet if desired

    • filterContext: an object containing variables attached to this filter. Any changes to this object will be visible to all invocations of this filter.

    • connectionContext: an object containing variables attached to the connection. Any changes to this object will be visible to all filters defined on this connection.