10

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.

Kevin Burke
  • 61,194
  • 76
  • 188
  • 305

2 Answers2

14

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.

Stennie
  • 63,885
  • 14
  • 149
  • 175
0

You can control where this file will be created.

So take a look here.

void shellHistoryInit() {
    stringstream ss;
    const char* h = shell_utils::getUserDir();
    if (h)
        ss << h << "/";
    ss << ".dbshell";
    historyFile = ss.str();

    linenoiseHistoryLoad(historyFile.c_str());
    linenoiseSetCompletionCallback(completionHook);
}

so if you return falsy value from this function the file should not be created:

const char* getUserDir() {
#ifdef _WIN32
    return getenv("USERPROFILE");//make sure this is empty
#else
    return getenv("HOME");
#endif
}
Tal Avissar
  • 10,088
  • 6
  • 45
  • 70