Search code examples
mongodbprivacy

How to disable the mongo .dbshell history file


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.


Solution

  • 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.