I am trying to use the MongoDB shell to run some scripts. Inside the JavaScript I am attempting to run var map = new Map() then map.set(1,1).

However, I am getting the following error:

E QUERY    [js] TypeError: map.set is not a function :

I am running this mongo shell version: MongoDB shell version v4.2.1

Does the mongo shell not support the map.set() function?


No, they hide the standard implementation in implscope.cpp

// This builtin map is a javascript 6 thing. We want our version. so // take theirs out

and implement a new one in types.js.

Well, you can workaround doing:

Map.prototype.set = Map.prototype.put

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.