本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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);
}
示例5: RunCommandsAsync
private async Task RunCommandsAsync(IMongoDatabase database, IEnumerable<BsonDocument> commands)
{
foreach (var command in commands)
{
await database.RunCommandAsync(new BsonDocumentCommand<BsonDocument>(command));
}
}