Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
Click here >
Docs Menu
Docs Home
/

Server-side JavaScript

Important

Map-reduce is deprecated starting in MongoDB 5.0.

MongoDB provides the following operators that perform server-side execution of JavaScript code:

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

To disable all server-side execution of JavaScript for mongod or mongos, you can either:

Although server-side methods use JavaScript, most interactions with MongoDB do not use JavaScript but instead use an idiomatic driver in the language of the interacting application.

Refer to the individual method or operator documentation for any concurrency information. See also the concurrency table.

MongoDB 6.0 upgrades the internal JavaScript engine used for server-side JavaScript, $accumulator, $function, and $where expressions and from MozJS-60 to MozJS-91. Several deprecated, non-standard array and string functions that existed in MozJS-60 are removed in MozJS-91.

If you use SELinux, any MongoDB operation that requires server-side JavaScript results in a segfault error. To disable execution of server-side JavaScript, see Disable Server-Side JavaScript.

Back

Server Sessions

On this page