Skip to content
Browse files

Merge branch 'master' of http://github.com/mongodb-csharp/mongodb-csharp

  • Loading branch information...
2 parents 7ed74d5 + 3a3d3c4 commit dc7618979fc9a24dad8907743a7987dd9be316af @testn testn committed Oct 22, 2010
Showing with 28 additions and 19 deletions.
  1. +17 −1 source/MongoDB/Connections/Connection.cs
  2. +11 −18 source/MongoDB/MongoCollection_1.cs
View
18 source/MongoDB/Connections/Connection.cs
@@ -247,11 +247,27 @@ public Document SendCommand(ISerializationFactory factory, string database, Type
public T SendCommand<T>(ISerializationFactory factory, string database, Type rootType, object command)
where T : CommandResultBase
{
+ return SendCommand<T>(factory, database, rootType, command, true);
+ }
+
+ /// <summary>
+ /// Sends the command.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="factory">The factory.</param>
+ /// <param name="database">The database.</param>
+ /// <param name="rootType">Type of serialization root.</param>
+ /// <param name="command">The spec.</param>
+ /// <param name="throw">if set to <c>true</c> [@throw].</param>
+ /// <returns></returns>
+ public T SendCommand<T>(ISerializationFactory factory, string database, Type rootType, object command, bool @throw)
+ where T : CommandResultBase
+ {
AuthenticateIfRequired(database);
var result = SendCommandCore<T>(factory, database, rootType, command);
- if(!result.Success)
+ if(@throw && !result.Success)
throw new MongoCommandException(result.ErrorMessage, null, null);
return result;
View
29 source/MongoDB/MongoCollection_1.cs
@@ -228,9 +228,7 @@ public T FindAndModify(object document, object spec, object sort, bool returnNew
/// <returns>A <see cref="Document"/></returns>
public T FindAndModify(object document, object spec, object sort, object fields, bool remove, bool returnNew, bool upsert)
{
- try
- {
- var command = new Document
+ var command = new Document
{
{"findandmodify", Name},
{"query", spec},
@@ -240,23 +238,18 @@ public T FindAndModify(object document, object spec, object sort, object fields,
{"upsert", upsert}
};
- if(sort != null)
- command.Add("sort", sort);
- if(fields != null)
- command.Add("fields", fields);
+ if(sort != null)
+ command.Add("sort", sort);
+ if(fields != null)
+ command.Add("fields", fields);
- var response = _connection.SendCommand<FindAndModifyResult<T>>(_configuration.SerializationFactory,
- DatabaseName,
- typeof(T),
- command);
+ var response = _connection.SendCommand<FindAndModifyResult<T>>(_configuration.SerializationFactory,
+ DatabaseName,
+ typeof(T),
+ command,
+ false);
- return response.Value;
- }
- catch(MongoCommandException)
- {
- // This is when there is no document to operate on
- return null;
- }
+ return response.Value;
}
/// <summary>

0 comments on commit dc76189

Please sign in to comment.
Something went wrong with that request. Please try again.