Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-597

Date.now() is not available

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 0.12.0
    • Affects Version/s: 0.7.7
    • Component/s: Shell API
    • Labels:
    • 1
    • Not Needed
    • Iteration Z

      The global `Date` object in mongosh is not the language built-in `Date`, unlike in the legacy shell. This breaks `Date.now()` usage.

      A simple way to solve this would be to make the `Date` BSON function inherit from the native `Date` function like ES6 classes do, i.e.

      Object.setPrototypeOf(BSONDate, JSDate);
      Object.setPrototypeOf(BSONDate.prototype, JSDate.prototype);
      

      However, as far as I can tell, the only difference between our shell-bson Date function and the builtin one is that, when multiple arguments are passed, our shell-bson Date function assumes UTC instead of the local timezone.

      This is mismatched with both Node.js and the legacy shell, and I’m wondering if it makes sense to just remove our custom Date function entirely.

            Assignee:
            anna.henningsen@mongodb.com Anna Henningsen
            Reporter:
            anna.henningsen@mongodb.com Anna Henningsen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: