当前位置: 首页>>代码示例>>C#>>正文


C# IMongoDatabase.RunCommandAsync方法代码示例

本文整理汇总了C#中IMongoDatabase.RunCommandAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IMongoDatabase.RunCommandAsync方法的具体用法?C# IMongoDatabase.RunCommandAsync怎么用?C# IMongoDatabase.RunCommandAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMongoDatabase的用法示例。


在下文中一共展示了IMongoDatabase.RunCommandAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GrantUserRole

 private static async Task GrantUserRole(IMongoDatabase db, string userName, string role, string dbName)
 {
     var command = new BsonDocument
     {
         {"grantRolesToUser", userName},
         {"roles", new BsonArray {new BsonDocument {{"role", role}, {"db", dbName}}}}
     };
     await db.RunCommandAsync<BsonDocument>(command);
 }
开发者ID:alexestevam,项目名称:UsersVoice,代码行数:9,代码来源:Program.cs

示例2: ExecuteMongoDBCommand

 /// <summary>
 /// 
 /// </summary>
 /// <param name="mongoCmd"></param>
 /// <param name="mongoDb"></param>
 /// <returns></returns>
 public static CommandResult ExecuteMongoDBCommand(CommandDocument mongoCmd, IMongoDatabase mongoDb)
 {
     CommandResult mCommandResult = null;
     try
     {
         var t = Task.Run(
             async () => { mCommandResult = await mongoDb.RunCommandAsync<CommandResult>(mongoCmd); }
             );
         t.Wait();
     }
     catch (MongoCommandException ex)
     {
         mCommandResult = new CommandResult(ex.Result);
     }
     var e = new RunCommandEventArgs
     {
         CommandString = mongoCmd.ToString(),
         RunLevel = EnumMgr.PathLevel.Database,
         Result = mCommandResult
     };
     OnCommandRunComplete(e);
     return mCommandResult;
 }
开发者ID:jango2015,项目名称:MongoCola,代码行数:29,代码来源:CommandHelper.cs

示例3: IsCappedCollection

        private static async Task<bool> IsCappedCollection(string collectionName, IMongoDatabase mongoDatabase)
        {
            var command = new BsonDocumentCommand<BsonDocument>(new BsonDocument
            {
                {"collstats", collectionName}
            });

            var stats = await mongoDatabase.RunCommandAsync(command);
            return stats["capped"].AsBoolean;
        }
开发者ID:AzharIqbal84,项目名称:ForwardMongoLogger,代码行数:10,代码来源:MongoDbHelper.cs

示例4: ConvertCollectionToCapped

        private static async Task<bool> ConvertCollectionToCapped(string collectionName, IMongoDatabase mongoDatabase, long? cappedCollectionSize, long? maxNumberOfDocuments)
        {
            var command = new BsonDocumentCommand<BsonDocument>(new BsonDocument
            {
                {"convertToCapped", collectionName},
                {"size",cappedCollectionSize ?? DefaultCappedCollectionSize },
                {"max",maxNumberOfDocuments ?? DefaultCappedCollectionMaxDocuments}
            });

            await mongoDatabase.RunCommandAsync(command);
            return await IsCappedCollection(collectionName, mongoDatabase);
        }
开发者ID:AzharIqbal84,项目名称:ForwardMongoLogger,代码行数:12,代码来源:MongoDbHelper.cs

示例5: RunCommandsAsync

 private async Task RunCommandsAsync(IMongoDatabase database, IEnumerable<BsonDocument> commands)
 {
     foreach (var command in commands)
     {
         await database.RunCommandAsync(new BsonDocumentCommand<BsonDocument>(command));
     }
 }
开发者ID:24,项目名称:mongo-csharp-driver,代码行数:7,代码来源:GridFSTestBase.cs


注:本文中的IMongoDatabase.RunCommandAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。