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