我阅读了 MongoDB 文档,但我不太了解!我需要知道以下代码是否正确!如果操作成功执行,我需要得到确认。需要调用 getLastError 还是 try-catch 就足够了?
public override bool DeleteUser(string username, bool deleteAllRelatedData)
{
WriteConcernResult result = null;
try
{
result = this.users.Remove(Query.And(Query.EQ("ApplicationName",
this.ApplicationName), Query.EQ("Username", username)), RemoveFlags.Single,
WriteConcern.Acknowledged);
if (result.HasLastErrorMessage)
{
return false;
}
return (result.DocumentsAffected == 1);
}
catch (Exception ex)
{
return false;
}
}