MongoDB supports JavaScript expressions in find()
statements. Just be aware that:
Javascript executes more slowly than the native operators [...] but is very flexible.
The JavaScript expression string is parsed into actual JavaScript once, which is then evaluated for each document.
However, the JavaScript is not converted to native operators, such as { $ne: 3 }
. The reason for this is that not all JavaScript can be expressed using native operators.
Because it cannot convert the expression into native operators, it (probably) also doesn't know which indexes to use. As a result, JavaScript expressions can be somewhat slower than native operators.