How to disable the mongo.dbshell history file

When I start the mongo client, it stores the command history in $ HOME / .dbshell. I would rather not write any commands from Mongo.

How to disable the behavior that is written to the .dbshell file? I don’t want to write it in / tmp, I want him not to write anywhere.

This page does not provide useful information here .

+6
source share
2 answers

As in MongoDB 3.4, there is no explicit option to disable the history function mongo.

A possible workaround is to create a read-only history file. The shell mongowill continue to work without errors if the file .dbshellcannot be read or written.

, Unix- :

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

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

MongoDB, , : SERVER-29103: .dbshell.

+10

, .

, .

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);
}

, , :

const char* getUserDir() {
#ifdef _WIN32
    return getenv("USERPROFILE");//make sure this is empty
#else
    return getenv("HOME");
#endif
}
-1

Source: https://habr.com/ru/post/1017039/


All Articles