Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-46243

Support ES6 Map object in MongoDB shell

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • None
    • Environment:
    • Server Tooling & Methods
    • Service Arch 2020-04-06, Service arch 2020-04-20

      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 ]
      
      

            Assignee:
            backlog-server-stm Backlog - Server Tooling and Methods (STM) (Inactive)
            Reporter:
            derek@echologic.com Derek Scherger
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: