What version of javascript is $accumulator using?

Im working on an aggregation pipeline, using the $accumulator function.

What version of javascript can I use when writing the code?

I seem to have issues with Object.entries() - and Atlas support send me here :sweat_smile:

Welcome to the MongoDB community @Alex_Bjorlig!

The most straightforward way to check the embedded JavaScript interpreter version is by calling interpreterVersion() in the mongo shell version matching your server release (both embed the same interpreter versions).

For MongoDB 4.4, the interpreter version is MozJS-60 (or more precisely from a peek at the source code, MozJS ESR 60.3). This ESR (Extended Support Release) version of MozJS was embedded in Firefox 63, and roughly corresponds to ECMAScript 2017 with some features from newer drafts: ECMAScript 2016 to ES.Next support in Mozilla.

If an $accumulator function isn’t working as expected, please share some more information. Example documents, aggregation pipeline, and expected vs actual output would be helpful.


Hi Stennie.

I guess what would be really help-full was a site like https://caniuse.com/.

When I look-up Object.entries() it lists the following support:

Screenshot 2021-01-12 at 14.27.28

If the javascript engine corresponds to Firefox 63 - then Object.entries() should work :+1:

Thanks for the help - and I guess my approach should be fine when determining what code I can use?

HI @Alex_Bjorlig,

Yes, referring to a guide on browser compatibility should generally work for core syntax. There are a few differences in the embedded JavaScript engine because this doesn’t include some of the browser APIs (like console output).

However, if something doesn’t work as expected I would start a forum discussion topic with more details so someone may be able to help with a solution or workaround.

For best performance and resource usage you should aim to minimise use of server-side JavaScript and try to use in-built aggregation operators.

For example, you can use array expression operators like $objectToArray to convert a document to an array, $map to apply an expression to each element of an array, or $filter to select a subset of an array based on an expression.


1 Like

Yeah - makes sense with the browser APIs not being there :slight_smile:

For more advanced use-cases the in-built aggregation operators are pretty limited, or at least they require a lot of steps.

So in our application, we are working on replacing some really long aggregation pipelines, and replace them with only 2 $group + $accumulator steps (and we use $filter to remove not-wanted data).

If you wan’t I could try to describe our data-format and desired output?