MongoDB provides the following commands, methods, and operator that
perform server-side execution of JavaScript code:

mapReduce and the corresponding mongo shell
method db.collection.mapReduce(). mapReduce operations
map, or associate, values to keys, and for keys with multiple
values, reduce the values for each key to a single object. For more
information, see Map-Reduce.

$where operator that evaluates a JavaScript expression or a
function in order to query for documents.

You can specify a JavaScript (.js) file to a mongo shell
instance to execute the file on the server. This is a good technique
for performing batch administrative work. When you run mongo
shell on the server, connecting via the localhost interface, the
connection is fast with low latency.