HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

MongoDB Shell support for map.set()

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
mapmongodbshellforsetsupport

Problem

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?

Solution

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

Code Snippets

Map.prototype.set = Map.prototype.put

Context

StackExchange Database Administrators Q#253561, answer score: 2

Revisions (0)

No revisions yet.