Unable to use a filter with profiling level

I’m using this as reference: command profile

I’m trying to set up a custom filter for the profiler. The filter I want to use is quite complex, but as a simple reproducer, let’s assume i just want to exclude queries from Compass and MongoShell from the profiler.

I’m using this command to set up the profiler:

profile: 2,
filter: {
appName: { $nin: [ “MongoDB Shell”, “MongoDB Compass” ] },

It doesn’t work and the profiler is still recording every query in system.profile, even those from Compass and MongoShell.

However, when I use the same filter expression in a find command, it works and it filters out the queries from the 2 apps I want to exclude:

appName: { $nin: [ “MongoDB Shell”, “MongoDB Compass” ] },

In short, I can’t make the filter option of the profiler work at all. Maybe a syntax error? Does anyone know how to use this?

I can reproduce this issue and it’s because you are setting profile level to 2 which means everything regardless of other settings. What you want is 1 which means only profile “matching” or “qualifying” operations.

Using profile level 1 this works as expected. Perhaps the docs should be a bit more clear.


1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.