[SERVER-46243] Support ES6 Map object in MongoDB shell Created: 18/Feb/20  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Derek Scherger Assignee: Backlog - Server Tooling and Methods (STM) (Inactive)
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

$ mongo --version
MongoDB shell version v4.2.3
git version: 6874650b362138df74be53d366bbefc321ea32d4
OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
allocator: tcmalloc
modules: none
build environment:
distmod: ubuntu1804
distarch: x86_64
target_arch: x86_64

mongos> interpreterVersion()
MozJS-60
mongos> db.serverBuildInfo()
{
"version" : "4.2.3",
"gitVersion" : "6874650b362138df74be53d366bbefc321ea32d4",
"modules" : [ ],
"allocator" : "tcmalloc",
"javascriptEngine" : "mozjs",
"sysInfo" : "deprecated",
"versionArray" : [
4,
2,
3,
0
],
"openssl" :

{ "running" : "OpenSSL 1.1.1 11 Sep 2018", "compiled" : "OpenSSL 1.1.1 11 Sep 2018" }

,
"buildEnvironment" :

{ "distmod" : "ubuntu1804", "distarch" : "x86_64", "cc" : "/opt/mongodbtoolchain/v3/bin/gcc: gcc (GCC) 8.2.0", "ccflags" : "-fno-omit-frame-pointer -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -O2 -Wno-unused-local-typedefs -Wno-unused-function -Wno-deprecated-declarations -Wno-unused-const-variable -Wno-unused-but-set-variable -Wno-missing-braces -fstack-protector-strong -fno-builtin-memcmp", "cxx" : "/opt/mongodbtoolchain/v3/bin/g++: g++ (GCC) 8.2.0", "cxxflags" : "-Woverloaded-virtual -Wno-maybe-uninitialized -fsized-deallocation -std=c++17", "linkflags" : "-pthread -Wl,-z,now -rdynamic -Wl,--fatal-warnings -fstack-protector-strong -fuse-ld=gold -Wl,--build-id -Wl,--hash-style=gnu -Wl,-z,noexecstack -Wl,--warn-execstack -Wl,-z,relro", "target_arch" : "x86_64", "target_os" : "linux" }

,
"bits" : 64,
"debug" : false,
"maxBsonObjectSize" : 16777216,
"ok" : 1,
"operationTime" : Timestamp(1582064070, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1582064070, 1),
"signature" :

{ "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) }

}
}


Issue Links:
Related
related to SERVER-50614 JS 'Set' type does not serialize well... Backlog
is related to SERVER-34281 ES6 arrow functions (lambdas) do not ... Closed
Assigned Teams:
Server Tooling & Methods
Sprint: Service Arch 2020-04-06, Service arch 2020-04-20
Participants:
Case:

 Description   

Mongo 3.2 release notes point out the change to use spidermonkey 

https://docs.mongodb.com/manual/release-notes/3.2-javascript/

and link to the ES6 standard

http://www.ecma-international.org/ecma-262/6.0/index.html
 http://www.ecma-international.org/ecma-262/6.0/index.html#sec-map-objects

However, it appears that the Map object does not work properly in MongoDB shell. The object returned from the constructor looks like a minimal map type of thing that doesn't conform to the ES6 standard.

mongos> m = new Map()
mongos> m = new Map(){ "_data" : { }, "put" : function(key, value) {    var o = this._get(key);    var old = o.value;    o.value = value;    return old;}, "get" : function(key) {    return this._get(key).value;}, "_get" : function(key) {    var h = Map.hash(key);    var a = this._data[h];    if (!a)
 
{        a = [];        this._data[h] = a;    }
 
    for (var i = 0; i < a.length; i++) {        if (friendlyEqual(key, a[i].key))
 
{            return a[i];        }
 
    }    var o = {key: key, value: null};    a.push(o);    return o;}, "values" : function() {    var all = [];    for (var k in this._data) {        this._data[k].forEach(function(z)
 
{            all.push(z.value);        }
 
);    }    return all;}}
 
mongos> m.clear()
 2020-02-18T15:20:53.945-0700 E  QUERY    [js] uncaught exception: TypeError: m.clear is not a function :@(shell):1:1
 
mongos> m.delete()
 2020-02-18T15:20:59.672-0700 E  QUERY    [js] uncaught exception: TypeError: m.delete is not a function :@(shell):1:1
 
mongos> m.entries()
 2020-02-18T15:21:05.374-0700 E  QUERY    [js] uncaught exception: TypeError: m.entries is not a function :@(shell):1:1
 
mongos> m.forEach()
 2020-02-18T15:21:11.367-0700 E  QUERY    [js] uncaught exception: TypeError: m.forEach is not a function :@(shell):1:1
 
mongos> m.get()
 null
 
mongos> m.has()
 2020-02-18T15:21:22.422-0700 E  QUERY    [js] uncaught exception: TypeError: m.has is not a function :@(shell):1:1
 
mongos> m.keys()
 2020-02-18T15:21:27.405-0700 E  QUERY    [js] uncaught exception: TypeError: m.keys is not a function :@(shell):1:1
 
mongos> m.set()
 2020-02-18T15:21:31.134-0700 E  QUERY    [js] uncaught exception: TypeError: m.set is not a function :@(shell):1:1
 
mongos> m.size
 
mongos> m.values()
 [ null ]



 Comments   
Comment by Robert Guo (Inactive) [ 06/Apr/21 ]

Hi derek@echologic.com, this feature is available in our new MongoDB Shell (mongosh) (see installation instructions here). mongosh is still in beta but it should have most of the functionality you need. As we are preparing to GA it later this year, feel free to reach out if you have any questions or feedback.

Comment by Adrien JOLY [ 25/Feb/21 ]

I'm having this issue too:

 

Similarly, I'm getting the following error when trying to access the `get()` method of a `Map`:

 

ReferenceError: friendlyEqual is not defined :
{{ Map.prototype._get@src/mongo/shell/types.js:578:1}}
{{ Map.prototype.get@src/mongo/shell/types.js:567:12}}

(ticket: https://jira.mongodb.org/browse/SERVER-19169)

Comment by Eric Sedor [ 24/Feb/20 ]

derek@echologic.com,

I'm passing along this request for consideration. Thanks again for this submission.

Eric

Comment by Eric Sedor [ 21/Feb/20 ]

Hi derek@echologic.com, thanks for your report. We'll take a look and get back to you if any questions come up.

Gratefully,
Eric

Generated at Thu Feb 08 05:10:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.