【问题标题】:use mongodb_name does not work in C# Process使用 mongodb_name 在 C# 进程中不起作用
【发布时间】:2016-04-07 13:36:50
【问题描述】:

我经常使用命令

使用 some_mongodb

在 Windows 上从命令提示符创建新数​​据库

当你想在 C# 进程中执行这个命令时,这个命令似乎不起作用

我有以下代码尝试从 C# 创建 mongo 数据库

ProcessStartInfo startInfo = new ProcessStartInfo
{
    UseShellExecute = false,
    RedirectStandardOutput = true,
    RedirectStandardError = true,
    RedirectStandardInput = true,
    WorkingDirectory = _mongoBinDir,
    FileName = "mongo.exe",
    Arguments = "use " + databaseTxt.Text
};

_mongoInsertProcess = new Process
{
    StartInfo = startInfo
};

_mongoInsertProcess.Start();

string stderrStr = _mongoInsertProcess.StandardError.ReadToEnd();
string stdoutStr = _mongoInsertProcess.StandardOutput.ReadToEnd();

stdoutStr变量获取值

"MongoDB shell 版本:3.2.1 连接到:使用 2016-04-07T15:28:52.875+0200 E - [主] 文件 [some_db] 没有 存在加载失败:some_db"

请就此提出建议。

【问题讨论】:

    标签: c# windows mongodb process


    【解决方案1】:

    use some_db 不是有效参数。只需传递数据库的名称,即:

    ProcessStartInfo startInfo = new ProcessStartInfo
    {
        UseShellExecute = false,
        RedirectStandardOutput = true,
        RedirectStandardError = true,
        RedirectStandardInput = true,
        WorkingDirectory = _mongoBinDir,
        FileName = "mongo.exe",
        Arguments = databaseTxt.Text
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-23
      • 1970-01-01
      • 2013-10-15
      • 1970-01-01
      • 1970-01-01
      • 2021-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多