[SERVER-37759] shell should merge history on exit Created: 26/Oct/18  Updated: 06/Dec/22  Resolved: 17/Dec/20

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

Type: Improvement Priority: Major - P3
Reporter: Kevin Pulo Assignee: Backlog - Server Tooling and Methods (STM) (Inactive)
Resolution: Won't Fix Votes: 1
Labels: move-stm
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Server Tooling & Methods
Sprint: 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
Participants:

 Description   

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()

   


 Comments   
Comment by Robert Guo (Inactive) [ 17/Dec/20 ]

We will no longer be adding new features to the old mongo shell outside of a small number of exceptions. Please consider switching to the new shell, mongosh, for general use cases.

If this ticket is desired for Server development, please reopen.

Comment by Asya Kamsky [ 21/Dec/18 ]

I'd like to add that it's more important not to lose commands than to keep the history file to its absolute limit (in my opinion)

Generated at Thu Feb 08 04:46:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.