Skip to content

DOCS-6615: Document 3.2 JavaScript changes #2442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/redirects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,13 @@ code: 303
outputs:
- 'before-v3.0'
---
from: '/release-notes/3.2-javascript'
to: '/release-notes'
type: 'redirect'
code: 303
outputs:
- 'before-v3.0'
---
from : '/core/index-partial'
to: '/core/index-sparse'
type: 'redirect'
Expand Down
10 changes: 10 additions & 0 deletions source/includes/options-mongo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,14 @@ inherit:
name: sslAllowInvalidHostnames
program: _shared
file: options-shared.yaml
---
program: mongo
name: disableJavaScriptJIT
directive: option
optional: true
args: null
description: |
.. versionadded:: 3.2

Disables use of the JavaScript engine's JIT compiler.
...
6 changes: 3 additions & 3 deletions source/reference/command/buildInfo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ These fields are stable and should provide consistent behavior.

.. data:: buildInfo.javascriptEngine

.. versionchanged:: 2.4
.. versionchanged:: 3.2

A string that reports the JavaScript engine used in the
:program:`mongod` instance. By default, this is ``V8`` after
version 2.4, and ``SpiderMonkey`` before 2.4.
:program:`mongod` instance. By default, this is ``mozjs`` after
version 3.2, and previously ``V8``.

.. data:: buildInfo.bits

Expand Down
4 changes: 4 additions & 0 deletions source/reference/command/setParameter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@ setParameter
- :parameter:`syncdelay`
- :parameter:`wiredTigerEngineRuntimeConfigSetting`

**JavaScript**

- :parameter:`disableJavaScriptJIT`

.. slave-ok, admin-only
.. textSearchEnabled, deprecated v2.6
39 changes: 34 additions & 5 deletions source/reference/parameters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ General Parameters
db.getSiblingDB('admin').runCommand( { setParameter: 1, failIndexKeyTooLong: false } )

You can also set :parameter:`failIndexKeyTooLong` at
run-time with the following operation.
startup time with the following option:

.. code-block:: sh

Expand Down Expand Up @@ -462,13 +462,42 @@ General Parameters

db.getSiblingDB('admin').runCommand( { setParameter: 1, ttlMonitorEnabled: false } )

Alternately, you may disable the thread at run-time by starting the
Alternately, you may disable the thread at startup time by starting the
:program:`mongod` instance with the following option:

.. code-block:: sh

mongod --setParameter ttlMonitorEnabled=false


.. parameter:: disableJavaScriptJIT

.. versionadded:: 3.2

|mongod-only|

The MongoDB JavaScript engine uses SpiderMonkey, which implements
Just-in-Time (JIT) compilation for improved performance when running scripts.

To disable the JIT, set :parameter:`disableJavaScriptJIT` to ``true``, as in
the following example:

.. code-block:: javascript

db.getSiblingDB('admin').runCommand( { setParameter: 1, disableJavaScriptJIT: true } )

Be aware that :dbcommand:`group` and :query:`$where` will reuse existing
JavaScript interpreter contexts, so changes to
:parameter:`disableJavaScriptJIT` may not take effect immediately for these
operations.

Alternately, you may disable the JIT at startup time by starting the
:program:`mongod` instance with the following option:

.. code-block:: sh

mongod --setParameter disableJavaScriptJIT=true

Logging Parameters
~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -585,7 +614,7 @@ Logging Parameters
} )

You can also set parameter :parameter:`logComponentVerbosity` at
run-time, passing the verbosity level document as a string.
startup time, passing the verbosity level document as a string.

:program:`mongo` shell also provides the :method:`db.setLogLevel()`
to set the log level for a single component. For various ways to set
Expand Down Expand Up @@ -653,7 +682,7 @@ To support the :ref:`diagnostic data capture
<3.2-diagnostic-data-capture>`, MongoDB introduces the following
parameters:

.. note::
.. note::

The default values for the diagnostic data capture interval and the
maximum sizes are chosen to provide useful data to MongoDB engineers
Expand Down Expand Up @@ -903,7 +932,7 @@ WiredTiger Parameters

.. code-block:: javascript

db.adminCommand({
db.adminCommand({
"setParameter": 1,
"wiredTigerEngineRuntimeConfig": "<option>=<setting>,<option>=<setting>"
})
Expand Down
2 changes: 2 additions & 0 deletions source/reference/program/mongo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Core Options

.. include:: /includes/option/option-mongo-<db address>.rst

.. include:: /includes/option/option-mongo-disableJavaScriptJIT.rst

.. _mongo-shell-file:

.. include:: /includes/option/option-mongo-<file.js>.rst
Expand Down
14 changes: 12 additions & 2 deletions source/release-notes/3.2-compatibility.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,18 @@ Aggregation Compatibility Changes
SpiderMonkey Compatibility Changes
----------------------------------

The change to SpiderMonkey may cause incompatibility issues for
JavaScript code that relies on specific V8 functionality/behavior.
.. class:: hidden

.. toctree::

/release-notes/3.2-javascript

MongoDB 3.2 changes the JavaScript engine from V8 to SpiderMonkey. The change
allows the use of more modern JavaScript language features, and comes along with
minor :program:`mongo` shell improvements and compatibility changes.

See :doc:`/release-notes/3.2-javascript` for more information about
this change.

.. _3.2-driver-compatibility:

Expand Down
56 changes: 56 additions & 0 deletions source/release-notes/3.2-javascript.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
=================================
JavaScript Changes in MongoDB 3.2
=================================

.. default-domain:: mongodb

In MongoDB 3.2, the javascript engine used for both the :program:`mongo` shell
and for server-side javascript in :program:`mongod` changed from V8 to
`SpiderMonkey <https://developer.mozilla.org/en-US/docs/SpiderMonkey>`_.

To confirm which JavaScript engine you are using, you can use either
:js:func:`interpreterVersion()` method in the :program:`mongo` shell and the
:data:`~buildInfo.javascriptEngine` field in the output of
:method:`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
<http://www.ecma-international.org/ecma-262/6.0/index.html>`_,
abbreviated as ES6. ES6 adds many new language features, including:

- `arrow functions
<http://www.ecma-international.org/ecma-262/6.0/index.html#sec-arrow-function-definitions>`_,

- `destructuring assignment
<http://www.ecma-international.org/ecma-262/6.0/index.html#sec-destructuring-assignment>`_,

- `for-of loops
<http://www.ecma-international.org/ecma-262/6.0/index.html#sec-for-in-and-for-of-statements>`_, and

- `generators
<http://www.ecma-international.org/ecma-262/6.0/index.html#sec-generator-function-definitions>`_.

Changes to the ``mongo`` Shell
------------------------------

MongoDB 3.2 will return JavaScript and BSON
:bsontype:`undefined <data_undefined>` values intact if saved into a collection.
Previously, the :program:`mongo` shell would convert ``undefined`` values into
``null``.

MongoDB 3.2 also adds the :parameter:`disableJavaScriptJIT` parameter to
:program:`mongod`, which allows you to disable the JavaScript engine's JIT
acceleration. The :program:`mongo` shell has a corresponding
:option:`--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.