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

Support Date.timeFunc() from old shell?

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 0.15.0
    • Affects Version/s: 0.12.0
    • Component/s: Shell API
    • None
    • Needed
    • Hide

      Not sure if we need docs specifically for this or if it will be already covered in the docs for snippets. I think it's worth pointing out somewhere in the docs that while some helpers/methods and the additions to the JS native types are not available by default in mongosh and users should rather use cleaner options that are availabe in JS/Node, they can still install a backwards compatibility snippet with the shell command snippet install mongocompat.

      Show
      Not sure if we need docs specifically for this or if it will be already covered in the docs for snippets. I think it's worth pointing out somewhere in the docs that while some helpers/methods and the additions to the JS native types are not available by default in mongosh and users should rather use cleaner options that are availabe in JS/Node, they can still install a backwards compatibility snippet with the shell command snippet install mongocompat .

      Problem Description

      I was testing out my .mongorc.js for the first time in the 0.12.0 version and I noticed we don’t support Date.timeFunc() yet. Is that something we might consider?

      See: https://github.com/mongodb/mongo/blob/master/src/mongo/shell/types.js#L28

      I use it to do very quick perf testing in the shell, e.g.,

      function avgTime(func, runs) {
          a = [];
          runs = runs || 10;    for (var i=0; i<runs; i++) {
              a.push(Date.timeFunc(func))
          }    out = { avg: Array.avg(a), stdDev: Array.stdDev(a) };
          out.sampStdDev = Math.sqrt((1/(runs-1)) * (out.stdDev*out.stdDev));
          return out;
      }
      
      avgTime(function() {db.zips.aggregate({$group:{_id: '$state', count: $sum:'$pop'}}})}, 30)
       

      Steps to Reproduce

      Expected Results

      Actual Results

      Additional Notes

            Assignee:
            Unassigned Unassigned
            Reporter:
            dan@mongodb.com Daniel Pasette (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: