How to disable the mongo .dbshell history file

Kevin Burke picture Kevin Burke · May 6, 2017 · Viewed 7.8k times · Source

When I run the mongo client, it stores a history of commands in $HOME/.dbshell. I would prefer not to log any commands from Mongo.

How do I disable the behavior that writes to the .dbshell file? I don't want to write it to /tmp, I want to avoid having it write anywhere.

This page does not provide useful information here.

Answer

Stennie picture Stennie · May 8, 2017

As at MongoDB 3.4, there is no explicit option to disable the mongo shell history feature.

A possible workaround is to make the history file read-only. The mongo shell will currently continue without error if the .dbshell file cannot be read or written.

For example, on a Unix-like system:

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

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

I've raised a feature suggestion for this in the MongoDB issue tracker which you can watch, upvote, or comment on: SERVER-29103: Add option to disable writing shell history to .dbshell.