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

shell should merge history on exit

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • Server Tooling & Methods
    • Service Arch 2018-12-03, Service Arch 2018-12-17, Service Arch 2018-12-31, Service Arch 2019-01-14, Service Arch 2019-01-28, Service Arch 2019-02-11, Service Arch 2019-02-25, Service Arch 2019-03-11, Service Arch 2019-03-25, Service Arch 2019-04-08

      Currently on exit the shell outputs to the history file its entire buffer of commands. This is a problem when you have concurrent shells open, because it means that only the last shell exited wins (in terms of commands performed during these concurrent shell sessions).

      Much better would be if the shell tracked which commands were performed in this session, and then ensured that only those new commands are added to the end of the history file (which may have changed since the shell was started up).

      This is how bash works (and I expect also all other Unix shells which support command history).

      This is complicated by needing to ensure that the number of lines in the history file is correctly limited. Probably what is needed is to re-read the history file, skip the first N lines, and then output the following max-N lines plus the N lines from this session (unless N > max, in which case, the existing behaviour is fine).

      Terminal 1 Terminal 2 Terminal 3
      $ tail -1 .dbshell
      db.test.find()
      
         
       
      $ mongo
      MongoDB shell version v4.0.3
      connecting to: mongodb://127.0.0.1:27017
      ...
      > 
      
       
         
      $ mongo
      MongoDB shell version v4.0.3
      connecting to: mongodb://127.0.0.1:27017
      ...
      > foo
      2018-10-25T20:19:35.636-0400 E QUERY    [js] ReferenceError: foo is not defined :
      @(shell):1:1
      > bar
      2018-10-25T20:19:36.028-0400 E QUERY    [js] ReferenceError: bar is not defined :
      @(shell):1:1
      > baz
      2018-10-25T20:19:37.332-0400 E QUERY    [js] ReferenceError: baz is not defined :
      @(shell):1:1
      > exit
      bye
      
      $ tail -1 .dbshell
      baz
      
         
       
      > exit
      bye
      
       
      $ tail -1 .dbshell
      db.test.find()
      
         

            Assignee:
            backlog-server-stm Backlog - Server Tooling and Methods (STM) (Inactive)
            Reporter:
            kevin.pulo@mongodb.com Kevin Pulo
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: