使用 mongodb_name 在 C# 进程中不起作用

use mongodb_name does not work in C# Process

我经常使用命令

使用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 version: 3.2.1 connecting to: use 2016-04-07T15:28:52.875+0200 E - [main] file [some_db] doesn't exist failed to load: some_db"

请指教

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

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