本文整理汇总了C#中MongoDB.Driver.CommandDocument类的典型用法代码示例。如果您正苦于以下问题:C# CommandDocument类的具体用法?C# CommandDocument怎么用?C# CommandDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandDocument类属于MongoDB.Driver命名空间,在下文中一共展示了CommandDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnableSharding
/// <summary>
/// 数据库分片
/// </summary>
/// <param name="routeSvr"></param>
/// <param name="shardingDB"></param>
/// <returns></returns>
public static CommandResult EnableSharding(MongoServer routeSvr, String shardingDB)
{
CommandDocument mongoCmd = new CommandDocument();
mongoCmd = new CommandDocument();
mongoCmd.Add("enablesharding", shardingDB);
return ExecuteMongoCommand(mongoCmd, routeSvr);
}
示例2: FillClientStatusToList
/// <summary>
/// </summary>
/// <param name="trvSvrStatus"></param>
/// <param name="mongoConnClientLst"></param>
public static void FillClientStatusToList(CtlTreeViewColumns trvSvrStatus,
Dictionary<string, MongoClient> mongoConnClientLst)
{
var srvDocList = new List<BsonDocument>();
foreach (var mongoSvrKey in mongoConnClientLst.Keys)
{
try
{
var mongoClient = mongoConnClientLst[mongoSvrKey];
//flydreamer提供的代码
// 感谢 魏琼东 的Bug信息,一些命令必须以Admin执行
if (RuntimeMongoDbContext.GetServerConfigBySvrPath(mongoSvrKey).LoginAsAdmin)
{
var adminDb = mongoClient.GetDatabase(ConstMgr.DatabaseNameAdmin);
//Can't Convert IMongoDB To MongoDB
var command = new CommandDocument {{CommandHelper.ServerStatusCommand.CommandString, 1}};
var serverStatusDoc =
CommandHelper.ExecuteMongoDBCommand(command, adminDb).Response;
srvDocList.Add(serverStatusDoc);
}
}
catch (Exception ex)
{
Utility.ExceptionDeal(ex);
}
}
UiHelper.FillDataToTreeView("Server Status", trvSvrStatus, srvDocList, 0);
//打开第一层
foreach (TreeNode item in trvSvrStatus.DatatreeView.Nodes)
{
item.Expand();
}
}
示例3: TestCodeMissing
public void TestCodeMissing()
{
var command = new CommandDocument("invalid", 1);
var document = new BsonDocument();
var result = new CommandResult(command, document);
Assert.IsFalse(result.Code.HasValue);
}
示例4: ExecuteJsShell
/// 注意:有些命令可能只能用在mongos上面,例如addshard
/// <summary>
/// 使用Shell Helper命令
/// </summary>
/// <param name="JsShell"></param>
/// <param name="mongoSvr"></param>
/// <returns></returns>
public static CommandResult ExecuteJsShell(String JsShell, MongoServer mongoSvr)
{
var ShellCmd = new BsonDocument {{"$eval", new BsonJavaScript(JsShell)}, {"nolock", true}};
//必须nolock
var mongoCmd = new CommandDocument();
mongoCmd.AddRange(ShellCmd);
return ExecuteMongoSvrCommand(mongoCmd, mongoSvr);
}
示例5: ExecuteJsShell
/// <summary>
/// 使用Shell Helper命令
/// </summary>
/// <param name="JsShell"></param>
/// <param name="mongoSvr"></param>
/// <returns></returns>
public static CommandResult ExecuteJsShell(String JsShell, MongoServer mongoSvr)
{
BsonDocument cmd = new BsonDocument();
cmd.Add("$eval", new BsonJavaScript(JsShell));
//必须nolock
cmd.Add("nolock", true);
CommandDocument mongoCmd = new CommandDocument() { cmd };
return ExecuteMongoCommand(mongoCmd, mongoSvr);
}
示例6: TestCode
public void TestCode()
{
var command = new CommandDocument("invalid", 1);
var document = new BsonDocument("code", 18);
var result = new CommandResult(command, document);
Assert.IsTrue(result.Code.HasValue);
Assert.AreEqual(18, result.Code);
}
示例7: btnSearch_Click
/// <summary>
/// 全文检索功能
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSearch_Click(object sender, EventArgs e)
{
var textSearchCommand = new CommandDocument
{
{ "text", SystemManager.GetCurrentCollection().Name },
{ "search", txtKey.Text }
};
CommandResult SearchResult = SystemManager.GetCurrentCollection().Database.RunCommand(textSearchCommand);
MongoDBHelper.FillDataToTreeView("MapReduce Result", trvResult, SearchResult.Response);
}
示例8: TestOkMissing
public void TestOkMissing() {
var command = new CommandDocument("invalid", true);
var document = new BsonDocument();
var result = new CommandResult(command, document);
try {
var dummy = result.Ok;
} catch (MongoCommandException ex) {
Assert.IsTrue(ex.Message.StartsWith("Command 'invalid' failed: response has no ok element (response: "));
}
}
示例9: Count
/// <summary>
/// 执行Count(指定路劲)
/// </summary>
/// <param name="QueryDoc"></param>
/// <param name="databaseName"></param>
/// <param name="collectionName"></param>
/// <returns></returns>
public static CommandResult Count(BsonDocument QueryDoc, string databaseName, string collectionName)
{
//db.runCommand( { aggregate: "people", pipeline: [<pipeline>] } )
var aggrCmd = new CommandDocument
{
new BsonElement("count", new BsonString(collectionName)),
new BsonElement("query", QueryDoc)
};
var aggregateCommand = new MongoCommand(aggrCmd, EnumMgr.PathLevel.Database, databaseName);
return ExecuteMongoCommand(aggregateCommand);
}
示例10: Aggregate
/// <summary>
/// 执行聚合
/// </summary>
/// <param name="aggregateDoc"></param>
/// <returns></returns>
/// <param name="collectionName"></param>
public static CommandResult Aggregate(BsonArray aggregateDoc, string collectionName)
{
//db.runCommand( { aggregate: "people", pipeline: [<pipeline>] } )
var aggrCmd = new CommandDocument
{
new BsonElement("aggregate", new BsonString(collectionName)),
new BsonElement("pipeline", aggregateDoc)
};
var aggregateCommand = new MongoCommand(aggrCmd, EnumMgr.PathLevel.Database);
return ExecuteMongoCommand(aggregateCommand);
}
示例11: TestMaxMessageLengthWhenNotServerSuppliedUsesMaxBsonObjectSizeWhenLargerThanMongoDefaults
public void TestMaxMessageLengthWhenNotServerSuppliedUsesMaxBsonObjectSizeWhenLargerThanMongoDefaults()
{
var command = new CommandDocument("ismaster", 1);
var document = new BsonDocument
{
{ "ok", 1 },
{ "maxBsonObjectSize", MongoDefaults.MaxMessageLength }
};
var result = new IsMasterResult();
result.Initialize(command, document);
Assert.AreEqual(MongoDefaults.MaxMessageLength + 1024, result.MaxMessageLength);
}
示例12: TestMaxMessageLengthWhenServerSupplied
public void TestMaxMessageLengthWhenServerSupplied()
{
var command = new CommandDocument("ismaster", 1);
var document = new BsonDocument
{
{ "ok", 1 },
{ "maxMessageSizeBytes", 1000 },
{ "maxBsonObjectSize", 1000 }
};
var result = new IsMasterResult();
result.Initialize(command, document);
Assert.AreEqual(1000, result.MaxMessageLength);
}
示例13: TestOkMissing
public void TestOkMissing()
{
var command = new CommandDocument("invalid", 1);
var document = new BsonDocument();
var result = new CommandResult(document) { Command = command };
try
{
var dummy = result.Ok;
}
catch (MongoCommandException ex)
{
Assert.IsTrue(ex.Message.StartsWith("Command 'invalid' failed. Response has no ok element (response was ", StringComparison.Ordinal));
}
}
示例14: AddSharding
/// <summary>
/// 增加数据分片
/// </summary>
/// <param name="routeSvr"></param>
/// <param name="replicaSetName"></param>
/// <param name="shardingNames"></param>
/// <returns></returns>
public static CommandResult AddSharding(MongoServer routeSvr, string replicaSetName, List<string> shardingNames)
{
BsonDocument config = new BsonDocument();
BsonDocument cmd = new BsonDocument();
BsonDocument host = new BsonDocument();
string cmdPara = replicaSetName + "/";
foreach (var item in shardingNames)
{
cmdPara += SystemManager.ConfigHelperInstance.ConnectionList[item].IpAddr + ":" + SystemManager.ConfigHelperInstance.ConnectionList[item].Port.ToString() + ",";
}
cmdPara = cmdPara.TrimEnd(",".ToCharArray());
CommandDocument mongoCmd = new CommandDocument();
mongoCmd.Add("addshard", cmdPara);
return ExecuteMongoCommand(mongoCmd, routeSvr);
}
示例15: Aggregate
public static CommandResult Aggregate(BsonArray AggregateDoc)
{
//db.runCommand( { aggregate: "people", pipeline: [<pipeline>] } )
try
{
CommandDocument agg = new CommandDocument();
agg.Add(new BsonElement("aggregate", new BsonString(SystemManager.GetCurrentCollection().Name)));
agg.Add(new BsonElement("pipeline", AggregateDoc));
MongoCommand Aggregate_Command = new MongoCommand(agg, PathLv.DatabaseLV);
return ExecuteMongoCommand(Aggregate_Command, false);
}
catch (Exception ex)
{
SystemManager.ExceptionDeal(ex);
return new CommandResult(new BsonDocument());
}
}