C#蒙戈RunCommandAsync [英] C# Mongo RunCommandAsync

查看:533
本文介绍了C#蒙戈RunCommandAsync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以运行

db.Users.createIndex({"FirstName" : 1, "LastName": 1});



从RunCommandAsync也是有什么可以从命令来完成的例子。

from the RunCommandAsync also are there examples of what can be done from the command.

作为一个测试,我试过,但它通过异常运行此

As a test I tried to run this but it through an exception

var indexCommand = new BsonDocumentCommand<BsonDocument>(new BsonDocument{
        {"getIndexes", "Users"}
});
var results = await database.RunCommandAsync(indexCommand);



我知道我可以获取和创建从C#驱动指标,但是我想保持一个脚本在那些想通过C#来建立索引和那些想直接处理它的数据库之间的同步。

I know I can get and create indexes from the C# drivers, however I would like to keep a script in sync between those that want to build the indexes through C# and those that want to handle it directly on the DB.

推荐答案

您或许可以尝试另一种方法。特别是如果你看到了什么RunCommandAsync有望与BsonDocument做。请参见为RunCommandAsync <单元测试/一>

You could probably try an alternative method. Especially if you see what RunCommandAsync is expected to do with the BsonDocument. See Unit test for RunCommandAsync

假设你正在使用MongoDB的3.0,你可以考虑另一种下面的代码?

Assuming you are using mongodb 3.0, can you consider the code below an alternative?

    using (var results = await context.Users.Indexes.ListAsync())
    {
        while (await results.MoveNextAsync())
        {
            foreach (var current in results.Current)
            {
                System.Diagnostics.Debug.WriteLine(current["name"].AsString);
            }
        }
    }

这篇关于C#蒙戈RunCommandAsync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆