Fix This Page

JavaScript Changes in MongoDB 3.2

In MongoDB 3.2, the javascript engine used for both the mongo shell and for server-side javascript in mongod changed from V8 to SpiderMonkey.

To confirm which JavaScript engine you are using, you can use either interpreterVersion() method in the mongo shell and the javascriptEngine field in the output of db.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 6th edition of ECMAScript, abbreviated as ES6. ES6 adds many new language features, including:

Changes to the mongo Shell

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

MongoDB 3.2 also adds the disableJavaScriptJIT parameter to mongod, which allows you to disable the JavaScript engine’s JIT acceleration. 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 stack traces, you can capture the Error().stack property as a workaround.