本文整理汇总了C#中MongoDB.Driver.CommandDocument.Add方法的典型用法代码示例。如果您正苦于以下问题:C# CommandDocument.Add方法的具体用法?C# CommandDocument.Add怎么用?C# CommandDocument.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.CommandDocument
的用法示例。
在下文中一共展示了CommandDocument.Add方法的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: 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());
}
}
示例3: AddSharding
/// <summary>
/// 增加数据分片
/// </summary>
/// <param name="routeSvr"></param>
/// <param name="replicaSetName"></param>
/// <param name="lstAddress"></param>
/// <remarks>注意:有个命令可能只能用在mongos上面</remarks>
/// <returns></returns>
public static CommandResult AddSharding(MongoServer routeSvr, String replicaSetName, List<String> lstAddress, String Name, Decimal MaxSize)
{
// replset/host:port,host:port
String cmdPara = replicaSetName == String.Empty ? String.Empty : (replicaSetName + "/");
foreach (String item in lstAddress)
{
cmdPara += item + ",";
}
cmdPara = cmdPara.TrimEnd(",".ToCharArray());
CommandDocument mongoCmd = new CommandDocument();
mongoCmd.Add("addshard", cmdPara);
if (MaxSize != 0)
{
mongoCmd.Add("maxSize", (BsonValue)MaxSize);
}
if (Name != String.Empty)
{
mongoCmd.Add("name", Name);
}
return ExecuteMongoSvrCommand(mongoCmd, routeSvr);
}
示例4: 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);
}
示例5: ExecuteMongoColCommand
/// <summary>
/// 数据集命令
/// </summary>
/// <param name="Command">命令关键字</param>
/// <param name="mongoCol">数据集</param>
/// <param name="ExtendInfo">命令参数</param>
/// <returns></returns>
public static CommandResult ExecuteMongoColCommand(String Command, MongoCollection mongoCol, BsonDocument ExtendInfo)
{
var textSearchCommand = new CommandDocument
{
{ Command, mongoCol.Name },
};
foreach (var item in ExtendInfo.Elements)
{
textSearchCommand.Add(item);
}
var mCommandResult = mongoCol.Database.RunCommand(textSearchCommand);
RunCommandEventArgs e = new RunCommandEventArgs();
e.CommandString = textSearchCommand.ToString();
e.RunLevel = PathLv.CollectionLV;
e.Result = mCommandResult;
OnCommandRunComplete(e);
return mCommandResult;
}
示例6: AddSharding
//从MongoDB3.4开始,使用Zone来代替Tag了
/// <summary>
/// 增加数据分片
/// </summary>
/// <param name="routeSvr"></param>
/// <param name="replicaSetName"></param>
/// <param name="lstAddress"></param>
/// <remarks>注意:有个命令可能只能用在mongos上面</remarks>
/// <returns></returns>
public static CommandResult AddSharding(MongoServer routeSvr, string replicaSetName, List<string> lstAddress,
string name, decimal maxSize)
{
// replset/host:port,host:port
var cmdPara = replicaSetName == string.Empty ? string.Empty : replicaSetName + "/";
foreach (var item in lstAddress)
{
cmdPara += item + ",";
}
cmdPara = cmdPara.TrimEnd(",".ToCharArray());
var mongoCmd = new CommandDocument { { "addshard", cmdPara } };
if (maxSize != 0)
{
mongoCmd.Add("maxSize", maxSize);
}
if (name != string.Empty)
{
mongoCmd.Add("name", name);
}
return ExecuteMongoSvrCommand(mongoCmd, routeSvr);
}
示例7: ExecuteMongoColCommand
/// <summary>
/// 数据集命令
/// </summary>
/// <param name="Command">命令关键字</param>
/// <param name="mongoCol">数据集</param>
/// <param name="ExtendInfo">命令参数</param>
/// <returns></returns>
public static CommandResult ExecuteMongoColCommand(String Command, MongoCollection mongoCol, BsonDocument ExtendInfo)
{
var textSearchCommand = new CommandDocument
{
{ Command, mongoCol.Name },
};
foreach (var item in ExtendInfo.Elements)
{
textSearchCommand.Add(item);
}
return mongoCol.Database.RunCommand(textSearchCommand);
}
示例8: createRole
/// <summary>
/// 添加自定义角色
/// </summary>
public static CommandResult createRole(MongoDatabase mongoDb, Role role)
{
var mongoCmd = new CommandDocument("createRole", role.Rolename);
var privileges = new BsonArray();
privileges.AddRange(role.Privileges.Select(x => x.AsBsonDocument()));
mongoCmd.Add("privileges", privileges);
var roles = new BsonArray();
roles.AddRange(role.Roles.Select(x => x.AsBsonValue()));
mongoCmd.Add("roles", roles);
return ExecuteMongoDBCommand(mongoCmd, mongoDb);
}
示例9: convertToCapped
/// <summary>
/// convertToCapped
/// </summary>
/// <param name="collectionName"></param>
/// <param name="size"></param>
/// <returns></returns>
public static CommandResult convertToCapped(string collectionName, long size, MongoDatabase db)
{
var mongoCmd = new CommandDocument { { "convertToCapped", collectionName } };
mongoCmd.Add("size", size);
return ExecuteMongoDBCommand(mongoCmd, db);
}
示例10: RemoveSharding
/// <summary>
/// 移除Shard
/// </summary>
/// <param name="routeSvr"></param>
/// <param name="ShardName"></param>
/// <returns></returns>
public static CommandResult RemoveSharding(MongoServer routeSvr, String ShardName)
{
CommandDocument mongoCmd = new CommandDocument();
mongoCmd.Add("removeshard", ShardName);
return ExecuteMongoSvrCommand(mongoCmd, routeSvr);
}
示例11: ExecuteMongoColCommand
/// <summary>
/// 数据集命令
/// </summary>
/// <param name="command">命令关键字</param>
/// <param name="mongoCol">数据集</param>
/// <param name="extendInfo">命令参数</param>
/// <returns></returns>
public static CommandResult ExecuteMongoColCommand(string command, MongoCollection mongoCol,
BsonDocument extendInfo)
{
var executeCommand = new CommandDocument
{
{command, mongoCol.Name}
};
foreach (var item in extendInfo.Elements)
{
executeCommand.Add(item);
}
var mCommandResult = mongoCol.Database.RunCommand(executeCommand);
var e = new RunCommandEventArgs
{
CommandString = executeCommand.ToString(),
RunLevel = EnumMgr.PathLevel.Collection,
Result = mCommandResult
};
OnCommandRunComplete(e);
return mCommandResult;
}
示例12: DoGetLogLevel
private void DoGetLogLevel()
{
try
{
var cmd = new CommandDocument("getParameter", new BsonInt32(1));
cmd.Add("logLevel", new BsonInt32(1));
var response = MongoUtilities.Create(_cnn).GetDatabase("admin").RunCommand(cmd).Response;
var level = response["logLevel"].AsInt32;
_control.Dispatcher.Invoke(new Action(() =>
{
_control.LogLevel.Value = level;
_control.LogLevel.ValueChanged += LogLevelValueChanged;
}));
}
catch (Exception ex)
{
Utilities.LogException(ex);
}
}
示例13: DoSetLogLevel
private void DoSetLogLevel(int level)
{
try
{
var cmd = new CommandDocument("setParameter", new BsonInt32(1));
cmd.Add("logLevel", new BsonInt32(level));
var response = MongoUtilities.Create(_cnn).GetDatabase("admin").RunCommand(cmd).Response;
}
catch (Exception ex)
{
Utilities.LogException(ex);
}
}
示例14: CreateBeginTransactionCommandDocument
/// <summary>
/// Creates the begin transaction command document.
/// </summary>
/// <returns></returns>
private CommandDocument CreateBeginTransactionCommandDocument()
{
var commandDocument = new CommandDocument {new BsonElement("beginTransaction", "1")};
switch (Options.Isolation)
{
default:
//case TransactionIsolation.Mvcc:
commandDocument.Add(new BsonElement("isolation", "mvcc"));
break;
case MongoTransactionIsolation.ReadUncommitted:
commandDocument.Add(new BsonElement("isolation", "readUncommitted"));
break;
case MongoTransactionIsolation.Serializable:
commandDocument.Add(new BsonElement("isolation", "serializable"));
break;
}
return commandDocument;
}
示例15: AddShardToZone
/// <summary>
/// AddShardToZone
/// </summary>
/// <param name="routeSvr">服务器</param>
/// <param name="shardName">Shard名称</param>
/// <param name="tagName">Tag名称</param>
/// <returns></returns>
public static CommandResult AddShardToZone(MongoServer routeSvr, string shardName, string zone)
{
var mongoCmd = new CommandDocument { { "addShardToZone", shardName } };
mongoCmd.Add("zone", zone);
return ExecuteMongoSvrCommand(mongoCmd, routeSvr);
}