本文整理匯總了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);
}