ABCoder
ABCoder

Reputation: 306

How do I clear the command history in the mongo shell

Is there a command to clear the history from within the mongo shell?

Upvotes: 16

Views: 10878

Answers (6)

Run:

sudo rm ~/.mongodb/mongosh/mongosh_repl_history

Once that's done, all of your history will have been deleted from the MongoDB Shell.

Upvotes: 1

Mr.Cat
Mr.Cat

Reputation: 330

If you're using MongoDB Shell as a standalone package, you will find the shell history file located in ~/.dbshell

If you're using the embedded MongoDB Shell inside MongoDB Compass, you will find the shell history file located in ~/.config/MongoDB Compass/MongoDB Compass/shell-history.json

Just empty the history file

Upvotes: 0

Penny Liu
Penny Liu

Reputation: 17408

Command history is stored in ~/.dbshell file.

For example, on a Unix-like system:

# Ensure an empty history file
echo "" > ~/.dbshell

# Remove rwx access to the history file
chmod 0 ~/.dbshell

Upvotes: 0

Fizer Khan
Fizer Khan

Reputation: 92745

MongoDB terminal history is stored inside the ~/.dbshellfile. Just empty the .dbshell file

 $ > ~/.dbshell

Versions of Windows mongo.exe earlier than 2.2.0 will save the .dbshell file in the mongo.exe working directory.

Upvotes: 5

praveena_kd
praveena_kd

Reputation: 545

You can clear contents on the shell by Ctrl + L

Upvotes: 4

Kyle Banker
Kyle Banker

Reputation: 4359

There should be a file called .dbshell in your home folder. Just delete it.

Upvotes: 37

Related Questions