JavaScript Changes in MongoDB 3.2

In MongoDB 3.2, the javascript engine used for both the mongo shelland for server-side javascript in mongod changed from V8 toSpiderMonkey.

To confirm which JavaScript engine you are using, you can use eitherinterpreterVersion() method in the mongo shell and thejavascriptEngine field in the output ofdb.serverBuildInfo()

In MongoDB 3.2, this will appear as MozJS-38 and mozjs, respectively.

Modernized JavaScript Implementation (ES6)

SpiderMonkey brings with it increased support for features defined in the 6thedition of ECMAScript,abbreviated as ES6. ES6 adds many new language features, including:

Changes to the mongo Shell

MongoDB 3.2 will return JavaScript and BSONundefined values intact if saved into a collection.Previously, the mongo shell would convert undefined values intonull.

MongoDB 3.2 also adds the disableJavaScriptJIT parameter tomongod, which allows you to disable the JavaScript engine’s JITacceleration. The mongo shell has a corresponding—disableJavaScriptJIT flag.

Removed Non-Standard V8 Features

SpiderMonkey does not allow the non-standard Error.captureStackTrace()function that prior versions of MongoDB supported. If you must record stacktraces, you can capture the Error().stack property as a workaround.