本文整理汇总了C#中MongoDB.Driver.CommandDocument.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# CommandDocument.AddRange方法的具体用法?C# CommandDocument.AddRange怎么用?C# CommandDocument.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.CommandDocument
的用法示例。
在下文中一共展示了CommandDocument.AddRange方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: ExecuteJsShell
/// <summary>
/// 使用Shell Helper命令
/// </summary>
/// <param name="JsShell"></param>
/// <param name="mongoSvr"></param>
/// <returns></returns>
public static CommandResult ExecuteJsShell(String JsShell, MongoServer mongoSvr)
{
BsonDocument ShellCmd = new BsonDocument();
ShellCmd.Add("$eval", new BsonJavaScript(JsShell));
//必须nolock
ShellCmd.Add("nolock", true);
CommandDocument mongoCmd = new CommandDocument();
mongoCmd.AddRange(ShellCmd);
return ExecuteMongoSvrCommand(mongoCmd, mongoSvr);
}
示例3: ExecuteMongoColCommand
/// <summary>
/// 执行数据集命令
/// </summary>
/// <param name="CommandString"></param>
/// <param name="mongoCol"></param>
/// <returns></returns>
public static CommandResult ExecuteMongoColCommand(String CommandString, MongoCollection mongoCol)
{
CommandResult mCommandResult;
BsonDocument BaseCommand = new BsonDocument();
BaseCommand.Add(CommandString, mongoCol.Name);
CommandDocument mongoCmd = new CommandDocument();
mongoCmd.AddRange(BaseCommand);
try
{
mCommandResult = mongoCol.Database.RunCommand(mongoCmd);
}
catch (MongoCommandException ex)
{
mCommandResult = ex.CommandResult;
}
RunCommandEventArgs e = new RunCommandEventArgs();
e.CommandString = CommandString;
e.RunLevel = PathLv.CollectionLV;
e.Result = mCommandResult;
OnCommandRunComplete(e);
return mCommandResult;
}
示例4: ExecuteMongoColCommand
/// <summary>
/// 执行数据集命令
/// </summary>
/// <param name="commandString"></param>
/// <param name="mongoCol"></param>
/// <returns></returns>
public static CommandResult ExecuteMongoColCommand(string commandString, MongoCollection mongoCol)
{
CommandResult mCommandResult;
var baseCommand = new BsonDocument { { commandString, mongoCol.Name } };
var mongoCmd = new CommandDocument();
mongoCmd.AddRange(baseCommand);
try
{
mCommandResult = mongoCol.Database.RunCommand(mongoCmd);
}
catch (MongoCommandException ex)
{
mCommandResult = new CommandResult(ex.Result);
}
var e = new RunCommandEventArgs
{
CommandString = commandString,
RunLevel = EnumMgr.PathLevel.CollectionAndView,
Result = mCommandResult
};
OnCommandRunComplete(e);
return mCommandResult;
}
示例5: InitReplicaSet
/// <summary>
/// 初始化副本(数据库版本 - 废止)
/// </summary>
/// <param name="replicaSetName">副本名称</param>
/// <param name="hostList">从属服务器列表</param>
/// <param name="configs"></param>
public static CommandResult InitReplicaSet(string replicaSetName, string hostList,
Dictionary<string, MongoConnectionConfig> configs)
{
//第一台服务器作为Primary服务器
var primarySetting = new MongoClientSettings
{
Server = new MongoServerAddress(configs[hostList].Host,
configs[hostList].Port),
ReadPreference = ReadPreference.PrimaryPreferred
};
//如果不设置的话,会有错误:不是Primary服务器,SlaveOK 是 False
var primarySvr = new MongoClient(primarySetting).GetServer();
var config = new BsonDocument();
var hosts = new BsonArray();
var replSetInitiateCmd = new BsonDocument();
var host = new BsonDocument();
//生成命令
host = new BsonDocument
{
{ConstMgr.KeyId, 1},
{
"host", configs[hostList].Host + ":" + configs[hostList].Port
}
};
hosts.Add(host);
config.Add(ConstMgr.KeyId, replicaSetName);
config.Add("members", hosts);
replSetInitiateCmd.Add("replSetInitiate", config);
var mongoCmd = new CommandDocument();
mongoCmd.AddRange(replSetInitiateCmd);
return ExecuteMongoSvrCommand(mongoCmd, primarySvr);
}
示例6: ExecuteMongoColCommand
/// <summary>
/// 执行数据集命令
/// </summary>
/// <param name="CommandString"></param>
/// <param name="mongoCol"></param>
/// <returns></returns>
public static CommandResult ExecuteMongoColCommand(String CommandString, MongoCollection mongoCol)
{
CommandResult mCommandResult;
var BaseCommand = new BsonDocument {{CommandString, mongoCol.Name}};
var mongoCmd = new CommandDocument();
mongoCmd.AddRange(BaseCommand);
try
{
mCommandResult = mongoCol.Database.RunCommand(mongoCmd);
}
catch (MongoCommandException ex)
{
mCommandResult = ex.CommandResult;
}
var e = new RunCommandEventArgs
{
CommandString = CommandString,
RunLevel = MongoDbHelper.PathLv.CollectionLv,
Result = mCommandResult
};
OnCommandRunComplete(e);
return mCommandResult;
}
示例7: InitReplicaSet
/// <summary>
/// 初始化副本
/// </summary>
/// <param name="replicaSetName">副本名称</param>
/// <param name="hostList">从属服务器列表</param>
public static CommandResult InitReplicaSet(String replicaSetName, String hostList)
{
//第一台服务器作为Primary服务器
var PrimarySetting = new MongoClientSettings
{
Server = new MongoServerAddress(SystemManager.ConfigHelperInstance.ConnectionList[hostList].Host,
SystemManager.ConfigHelperInstance.ConnectionList[hostList].Port),
ReadPreference = ReadPreference.PrimaryPreferred
};
//如果不设置的话,会有错误:不是Primary服务器,SlaveOK 是 False
MongoServer PrimarySvr = new MongoClient(PrimarySetting).GetServer();
var config = new BsonDocument();
var hosts = new BsonArray();
var replSetInitiateCmd = new BsonDocument();
var host = new BsonDocument();
//生成命令
host = new BsonDocument
{
{MongoDbHelper.KEY_ID, 1},
{
"host", SystemManager.ConfigHelperInstance.ConnectionList[hostList].Host + ":" +
SystemManager.ConfigHelperInstance.ConnectionList[hostList].Port
}
};
hosts.Add(host);
config.Add(MongoDbHelper.KEY_ID, replicaSetName);
config.Add("members", hosts);
replSetInitiateCmd.Add("replSetInitiate", config);
var mongoCmd = new CommandDocument();
mongoCmd.AddRange(replSetInitiateCmd);
return ExecuteMongoSvrCommand(mongoCmd, PrimarySvr);
}
示例8: InitReplicaSet
/// <summary>
/// 初始化副本
/// </summary>
/// <param name="mongoSvr">副本组主服务器</param>
/// <param name="replicaSetName">副本名称</param>
/// <param name="HostList">从属服务器列表</param>
public static CommandResult InitReplicaSet(String replicaSetName, String HostList)
{
//第一台服务器作为Primary服务器
MongoClientSettings PrimarySetting = new MongoClientSettings();
PrimarySetting.Server = new MongoServerAddress(SystemManager.ConfigHelperInstance.ConnectionList[HostList].Host,
SystemManager.ConfigHelperInstance.ConnectionList[HostList].Port);
//如果不设置的话,会有错误:不是Primary服务器,SlaveOK 是 False
PrimarySetting.ReadPreference = ReadPreference.PrimaryPreferred;
MongoServer PrimarySvr = new MongoClient(PrimarySetting).GetServer();
BsonDocument config = new BsonDocument();
BsonArray hosts = new BsonArray();
BsonDocument replSetInitiateCmd = new BsonDocument();
BsonDocument host = new BsonDocument();
//生成命令
host = new BsonDocument();
host.Add(KEY_ID, 1);
host.Add("host", SystemManager.ConfigHelperInstance.ConnectionList[HostList].Host + ":" + SystemManager.ConfigHelperInstance.ConnectionList[HostList].Port.ToString());
hosts.Add(host);
config.Add(KEY_ID, replicaSetName);
config.Add("members", hosts);
replSetInitiateCmd.Add("replSetInitiate", config);
CommandDocument mongoCmd = new CommandDocument();
mongoCmd.AddRange(replSetInitiateCmd);
return ExecuteMongoSvrCommand(mongoCmd, PrimarySvr);
}