Message request filter

This filter gets (potentially) invoked for every request packet of type MSG.


Parameters

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


Context

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 an MSG packet

    • matchPath : a list of lists of strings, set if the JSON expression parameter is specified. This will contain, for each expression, the path into the first document that satisfied the expression.

    • matchSection : if the JSON expression parameter is specified, which section of the message was the first match

    • 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.


Example

Let's assume that you want to intercept a message that looks like this:

{

update: "customers",

updates: [

{

q: {balance: {$eq: 0}},

u: <document or pipeline>,

upsert: false,

multi: false,

collation: <document>,

arrayFilters: <array>,

hint: <document|string>

},

...

],

ordered: <boolean>,

writeConcern: { <write concern> },

bypassDocumentValidation: <boolean>,

comment: <any>

}

You can create a message response filter with the following JSON expression:

update=customers;updates[+].q.balance.$eq=0

In this example, the value for the matchPath variable would be set to: [[update, customers], [updates, 0, balance, $eq]]