本文整理匯總了C#中MongoDB.Driver.CommandResult類的典型用法代碼示例。如果您正苦於以下問題:C# CommandResult類的具體用法?C# CommandResult怎麽用?C# CommandResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CommandResult類屬於MongoDB.Driver命名空間,在下文中一共展示了CommandResult類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: MongoSafeModeException
public MongoSafeModeException(
string message,
CommandResult commandResult
)
: base(message, commandResult)
{
}
示例2: TestErrorMessagePresent
public void TestErrorMessagePresent()
{
var document = new BsonDocument("errmsg", "An error message");
var result = new CommandResult();
result.Initialize(document);
Assert.AreEqual("An error message", result.ErrorMessage);
}
示例3: TestErrorMessageMissing
public void TestErrorMessageMissing()
{
var document = new BsonDocument();
var result = new CommandResult();
result.Initialize(document);
Assert.AreEqual("Unknown error", result.ErrorMessage);
}
示例4: TestErrorMessageNotString
public void TestErrorMessageNotString()
{
var document = new BsonDocument("errmsg", 3.14159);
var result = new CommandResult();
result.Initialize(document);
Assert.AreEqual("3.14159", result.ErrorMessage);
}
示例5: SaveEditorJavascript
/// <summary>
/// Save Edited Javascript
/// </summary>
/// <param name="jsName"></param>
/// <param name="jsCode"></param>
/// <param name="jsCol"></param>
/// <returns></returns>
public static string SaveEditorJavascript(string jsName, string jsCode, MongoCollection jsCol)
{
//標準的JS庫格式未知
if (QueryHelper.IsExistByKey(jsName))
{
var result = DropDocument(jsCol, (BsonString) jsName);
if (string.IsNullOrEmpty(result))
{
CommandResult resultCommand;
try
{
resultCommand = new CommandResult(
jsCol.Insert(new BsonDocument().Add(ConstMgr.KeyId, jsName).Add("value", jsCode)).Response);
}
catch (MongoCommandException ex)
{
resultCommand = new CommandResult(ex.Result);
}
if (resultCommand.Response["err"] == BsonNull.Value)
{
return string.Empty;
}
return resultCommand.Response["err"].ToString();
}
return result;
}
return string.Empty;
}
示例6: DropDocument
/// <summary>
/// 刪除單條數據
/// </summary>
/// <param name="mongoCol">表對象</param>
/// <param name="objectId">ObjectId</param>
/// <returns></returns>
public static string DropDocument(MongoCollection mongoCol, string objectId)
{
CommandResult result;
try
{
//有時候在序列化的過程中,objectId是由某個字段帶上[id]特性客串的,所以無法轉換為ObjectId對象
//這裏先嘗試轉換,如果可以轉換,則轉換
ObjectId seekId;
if (ObjectId.TryParse(objectId, out seekId))
{
//如果可以轉換,則轉換
result =
new CommandResult(
mongoCol.Remove(Query.EQ(ConstMgr.KeyId, seekId), WriteConcern.Acknowledged)
.Response);
}
else
{
//不能轉換則保持原狀
result =
new CommandResult(
mongoCol.Remove(Query.EQ(ConstMgr.KeyId, objectId), WriteConcern.Acknowledged)
.Response);
}
}
catch (MongoCommandException ex)
{
result = new CommandResult(ex.Result);
}
BsonElement err;
return !result.Response.TryGetElement("err", out err) ? string.Empty : err.ToString();
}
示例7: TestOkZero
public void TestOkZero()
{
var document = new BsonDocument("ok", 0);
var result = new CommandResult(document);
Assert.False(result.Ok);
Assert.NotNull(result.ErrorMessage);
}
示例8: TestOkFalse
public void TestOkFalse()
{
var document = new BsonDocument("ok", false);
var result = new CommandResult(null, document);
Assert.IsFalse(result.Ok);
Assert.IsNotNull(result.ErrorMessage);
}
示例9: TestOkTrue
public void TestOkTrue()
{
var document = new BsonDocument("ok", true);
var result = new CommandResult(null, document);
Assert.IsTrue(result.Ok);
Assert.IsNull(result.ErrorMessage);
}
示例10: AddToReplsetServer
//Replica Set Commands
//http://www.mongodb.org/display/DOCS/Replica+Set+Commands
//rs.help() show help
//rs.status() { replSetGetStatus : 1 }
//rs.initiate() { replSetInitiate : null } initiate
// with default settings
//rs.initiate(cfg) { replSetInitiate : cfg }
//rs.add(hostportstr) add a new member to the set
//rs.add(membercfgobj) add a new member to the set
//rs.addArb(hostportstr) add a new member which is arbiterOnly:true
//rs.remove(hostportstr) remove a member (primary, secondary, or arbiter) from the set
//rs.stepDown() { replSetStepDown : true }
//rs.conf() return configuration from local.system.replset
//db.isMaster() check who is primary
/// <summary>
/// 增加服務器
/// </summary>
/// <param name="mongoSvr">副本組主服務器</param>
/// <param name="HostPort">服務器信息</param>
/// <param name="IsArb">是否為仲裁服務器</param>
/// <returns></returns>
public static CommandResult AddToReplsetServer(MongoServer mongoSvr, String HostPort, int priority, Boolean IsArb)
{
CommandResult mCommandResult = new CommandResult(new BsonDocument());
try
{
if (!IsArb)
{
mCommandResult = ExecuteJsShell("rs.add({_id:" + mongoSvr.Instances.Length + 1 + ",host:'" + HostPort + "',priority:" + priority.ToString() + "});", mongoSvr);
}
else
{
//其實addArb最後也隻是調用了add方法
mCommandResult = ExecuteJsShell("rs.addArb('" + HostPort + "');", mongoSvr);
}
}
catch (EndOfStreamException)
{
}
catch (Exception ex)
{
throw ex;
}
return mCommandResult;
}
示例11: TestCodeMissing
public void TestCodeMissing()
{
var document = new BsonDocument();
var result = new CommandResult(document);
Assert.False(result.Code.HasValue);
}
示例12: MongoCommandException
/// <summary>
/// Initializes a new instance of the MongoCommandException class.
/// </summary>
/// <param name="message">The error message.</param>
/// <param name="commandResult">The command result.</param>
public MongoCommandException(
string message,
CommandResult commandResult
)
: this(message) {
this.commandResult = commandResult;
}
示例13: TestCode
public void TestCode()
{
var document = new BsonDocument("code", 18);
var result = new CommandResult(document);
Assert.True(result.Code.HasValue);
Assert.Equal(18, result.Code);
}
示例14: 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);
}
示例15: 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);
}