Request Filters - MongoDB

Request filters are filters that are invoked when a request is received from the database client. Request filters are given the opportunity to look at the request and do whatever they want with it: let it through, modify it, or reject it.

Request filters can potentially be called for every single type of request, such as authentication, close result set, and so on, but they are usually most useful for command requests.

A typical example is a query filter, which is called whenever a database query is received from the client. Query filters are given a chance to look at the request and do with it as they please.


All request filters define the following variables, which can be accessed from your JavaScript code:

  • log : A Logger object to output messages to the logging system

  • context : a container object with the following properties:

    • packet : the packet being processed

    • packetType : the type of the packet, equivalent to context.packet.getPacketType()

    • filterContext : the variables that persist through the life of the filter

    • adapterContext : the variables that persist through the life of this database connection

Request filters for MongoDB