MongoDB 2.4 Javascript Changes



The upcoming release of MongoDB 2.4 brings an exciting change to the JavaScript engine. Previously, MongoDB ran Spidermonkey 1.7, but going forward, MongoDB will be running V8, the open-source high-performance JavaScript engine from Google. This means that from now on, whenever JavaScript is executed, V8 will be running the show.

In this post we’ll examine the following primary impacts of this change:

  1. concurrency improvements
  2. modernized JavaScript implementation
  3. impacted features

Concurrency improvements

Previously, every query/command that used the JS interpreter had to acquire a mutex, thus serializing all JS work. Now, with V8 we have improved concurrency by allowing each JavaScript job to run on a separate core.

For example, if a user’s workload commonly involved 24 concurrent $where queries (each from a unique client), and they have a server with 24 cores, they should expect query execution times to be reduced by (roughly) a factor of 24.

Modernized JavaScript Implementation (ES5)

Today’s modern JavaScript environments like Google Chrome, Node.js, Mozilla Firefox, Microsoft Internet Explorer and Apple Safari all implement the 5th edition of ECMAscript. This edition, abbreviated as ES5, adds many new language features like standardized JSON, strict mode, function.bind(), array extensions, getters/setters and much more. With the switch to V8, MongoDB now also supports ES5, making it easier to develop and maintain migration scripts, MapReduce jobs, and more. Read the full release notes for more details.

Impacted features

Moving to V8 brings with it a few changes to be aware of when migrating applications to MongoDB version >= 2.4.

Additional Limitations for Map-Reduce and $where Operations

In MongoDB 2.4 a number of global functions and properties available in the shell, such as db, are no longer available to Map/Reduce/Finalize, $where and group. When upgrading to MongoDB 2.4, you will need to refactor your code if you are using any global shell functions or properties that are no longer available.

The following are available to MapReduce, group, and $where in MongoDB 2.4:


  • args
  • MaxKey
  • MinKey


  • assert()
  • BinData()
  • DBPointer()
  • DBRef()
  • doassert()
  • emit()
  • gc()
  • HexData()
  • hex_md5()
  • isNumber()
  • isObject()
  • ISODate()
  • isString()
  • Map()
  • MD5()
  • NumberInt()
  • NumberLong()
  • ObjectId()
  • print()
  • sleep()
  • Timestamp()
  • UUID()
  • version()

Non-standard Spidermonkey features removed

Spidermonkey implemented several non-standard JavaScript language extensions not found in V8. These removed features were not documented so minimal impact is expected. To find out more about the differences between the V8 and Spidermonkey MongoDB implementations, please read this.

With V8, MongoDB supports the ES5 implementation of Javascript with the following exceptions:

The following do not work on documents returned from MongoDB queries:

Additional detail is available in the release notes. Learn more about the 2.4 release in the upcoming webinar series.