如何禁用 mongo .dbshel​​l 历史文件

How to disable the mongo .dbshell history file

当我运行 mongo 客户端时,它在$HOME/.dbshel​​l 中存储命令历史记录。我不想记录来自 Mongo.

的任何命令

如何禁用写入 .dbshel​​l 文件的行为?我不想把它写到 /tmp,我想避免让它写在任何地方。

此页面未提供有用信息here

您可以控制创建此文件的位置。

所以 看看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);
}

因此,如果您 return 来自此函数的虚假值,则不应创建文件:

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

在 MongoDB 3.4 中,没有明确的选项来禁用 mongo shell 历史功能。

一种可能的解决方法是将历史文件设置为只读。如果无法读取或写入 .dbshell 文件,mongo shell 当前将继续而不会出现错误。

例如,在类 Unix 系统上:

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

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

我已经在 MongoDB 问题跟踪器中提出了一个功能建议,您可以观看、投票或发表评论:SERVER-29103: Add option to disable writing shell history to .dbshell