Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
More find and modify improvments.
Browse files Browse the repository at this point in the history
  • Loading branch information
lanwin committed Sep 6, 2010
1 parent e09bd0d commit 6397a0f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
5 changes: 3 additions & 2 deletions source/MongoDB/IMongoCollection_1.cs
Expand Up @@ -148,11 +148,12 @@ public interface IMongoCollection<T>
/// <param name="selector">The selector.</param> /// <param name="selector">The selector.</param>
/// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
/// <see cref="IndexOrder"/></param> /// <see cref="IndexOrder"/></param>
/// <param name="returnNew">if set to <c>true</c> [return new].</param>
/// <param name="fields">The fields.</param> /// <param name="fields">The fields.</param>
/// <param name="remove">if set to <c>true</c> [remove].</param>
/// <param name="returnNew">if set to <c>true</c> [return new].</param>
/// <param name="upsert">if set to <c>true</c> [upsert].</param> /// <param name="upsert">if set to <c>true</c> [upsert].</param>
/// <returns>A <see cref="Document"/></returns> /// <returns>A <see cref="Document"/></returns>
T FindAndModify(object document, object selector, object sort, bool returnNew,object fields,bool upsert); T FindAndModify(object document, object selector, object sort, object fields, bool remove, bool returnNew, bool upsert);


/// <summary> /// <summary>
/// Entrypoint into executing a map/reduce query against the collection. /// Entrypoint into executing a map/reduce query against the collection.
Expand Down
25 changes: 16 additions & 9 deletions source/MongoDB/MongoCollection_1.cs
Expand Up @@ -181,8 +181,9 @@ public T FindOne(string javascriptWhere)
/// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the</param> /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the</param>
/// <returns>A <see cref="Document"/></returns> /// <returns>A <see cref="Document"/></returns>
/// <see cref="IndexOrder"/> /// <see cref="IndexOrder"/>
public T FindAndModify(object document, object spec, object sort){ public T FindAndModify(object document, object spec, object sort)
return FindAndModify(document, spec, sort, false, null, false); {
return FindAndModify(document, spec, sort, null, false, false, false);
} }


/// <summary> /// <summary>
Expand All @@ -193,8 +194,9 @@ public T FindOne(string javascriptWhere)
/// <param name="spec"><see cref="Document"/> to find the document.</param> /// <param name="spec"><see cref="Document"/> to find the document.</param>
/// <param name="returnNew">if set to <c>true</c> [return new].</param> /// <param name="returnNew">if set to <c>true</c> [return new].</param>
/// <returns>A <see cref="Document"/></returns> /// <returns>A <see cref="Document"/></returns>
public T FindAndModify(object document, object spec, bool returnNew){ public T FindAndModify(object document, object spec, bool returnNew)
return FindAndModify(document, spec, new Document(), returnNew,null,false); {
return FindAndModify(document, spec, null, null, false, returnNew, false);
} }
/// <summary> /// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document /// Executes a query and atomically applies a modifier operation to the first document returning the original document
Expand All @@ -208,7 +210,7 @@ public T FindOne(string javascriptWhere)
/// <returns>A <see cref="Document"/></returns> /// <returns>A <see cref="Document"/></returns>
public T FindAndModify(object document, object spec, object sort, bool returnNew) public T FindAndModify(object document, object spec, object sort, bool returnNew)
{ {
return FindAndModify(document, spec, sort, returnNew, null, false); return FindAndModify(document, spec, sort, null, false, returnNew, false);
} }


/// <summary> /// <summary>
Expand All @@ -219,11 +221,12 @@ public T FindAndModify(object document, object spec, object sort, bool returnNew
/// <param name="spec"><see cref="Document"/> to find the document.</param> /// <param name="spec"><see cref="Document"/> to find the document.</param>
/// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
/// <see cref="IndexOrder"/></param> /// <see cref="IndexOrder"/></param>
/// <param name="returnNew">if set to <c>true</c> [return new].</param>
/// <param name="fields">The fields.</param> /// <param name="fields">The fields.</param>
/// <param name="remove">if set to <c>true</c> [remove].</param>
/// <param name="returnNew">if set to <c>true</c> [return new].</param>
/// <param name="upsert">if set to <c>true</c> [upsert].</param> /// <param name="upsert">if set to <c>true</c> [upsert].</param>
/// <returns>A <see cref="Document"/></returns> /// <returns>A <see cref="Document"/></returns>
public T FindAndModify(object document, object spec, object sort, bool returnNew,object fields,bool upsert) public T FindAndModify(object document, object spec, object sort, object fields, bool remove, bool returnNew, bool upsert)
{ {
try try
{ {
Expand All @@ -232,12 +235,16 @@ public T FindAndModify(object document, object spec, object sort, bool returnNew
{"findandmodify", Name}, {"findandmodify", Name},
{"query", spec}, {"query", spec},
{"update", EnsureUpdateDocument(document)}, {"update", EnsureUpdateDocument(document)},
{"sort", sort},
{"new", returnNew}, {"new", returnNew},
{"fields", fields}, {"remove", remove},
{"upsert", upsert} {"upsert", upsert}
}; };


if(sort != null)
command.Add("sort", sort);
if(fields != null)
command.Add("fields", fields);

var response = _connection.SendCommand<FindAndModifyResult<T>>(_configuration.SerializationFactory, var response = _connection.SendCommand<FindAndModifyResult<T>>(_configuration.SerializationFactory,
DatabaseName, DatabaseName,
typeof(T), typeof(T),
Expand Down
31 changes: 16 additions & 15 deletions source/MongoDB/Obsolete/IMongoCollection.cs
Expand Up @@ -125,7 +125,22 @@ public interface IMongoCollection
/// <param name="returnNew">if set to <c>true</c> [return new].</param> /// <param name="returnNew">if set to <c>true</c> [return new].</param>
/// <returns>A <see cref="Document"/></returns> /// <returns>A <see cref="Document"/></returns>
Document FindAndModify(Document document, Document selector, Document sort, bool returnNew); Document FindAndModify(Document document, Document selector, Document sort, bool returnNew);


/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="spec"><see cref="Document"/> to find the document.</param>
/// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
/// <see cref="IndexOrder"/></param>
/// <param name="fields">The fields.</param>
/// <param name="remove">if set to <c>true</c> [remove].</param>
/// <param name="returnNew">if set to <c>true</c> [return new].</param>
/// <param name="upsert">if set to <c>true</c> [upsert].</param>
/// <returns>A <see cref="Document"/></returns>
Document FindAndModify(Document document, Document spec, Document sort, Document fields, bool remove, bool returnNew, bool upsert);

/// <summary> /// <summary>
/// Maps the reduce. /// Maps the reduce.
/// </summary> /// </summary>
Expand Down Expand Up @@ -273,19 +288,5 @@ public interface IMongoCollection
/// <param name = "document">The document.</param> /// <param name = "document">The document.</param>
/// <param name = "safemode">if set to <c>true</c> [safemode].</param> /// <param name = "safemode">if set to <c>true</c> [safemode].</param>
void Save(Document document, bool safemode); void Save(Document document, bool safemode);

/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="spec"><see cref="Document"/> to find the document.</param>
/// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
/// <see cref="IndexOrder"/></param>
/// <param name="returnNew">if set to <c>true</c> [return new].</param>
/// <param name="fields">The fields.</param>
/// <param name="upsert">if set to <c>true</c> [upsert].</param>
/// <returns>A <see cref="Document"/></returns>
Document FindAndModify(Document document, Document spec, Document sort, bool returnNew, Document fields, bool upsert);
} }
} }
9 changes: 5 additions & 4 deletions source/MongoDB/Obsolete/MongoCollection.cs
Expand Up @@ -184,7 +184,7 @@ public Document FindAndModify(Document document, Document spec, bool returnNew)
/// <returns>A <see cref="Document"/></returns> /// <returns>A <see cref="Document"/></returns>
public Document FindAndModify(Document document, Document spec, Document sort, bool returnNew) public Document FindAndModify(Document document, Document spec, Document sort, bool returnNew)
{ {
return _collection.FindAndModify(document, spec, sort, returnNew, null, false); return _collection.FindAndModify(document, spec, sort, null, false, returnNew, false);
} }


/// <summary> /// <summary>
Expand All @@ -195,13 +195,14 @@ public Document FindAndModify(Document document, Document spec, Document sort, b
/// <param name="spec"><see cref="Document"/> to find the document.</param> /// <param name="spec"><see cref="Document"/> to find the document.</param>
/// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
/// <see cref="IndexOrder"/></param> /// <see cref="IndexOrder"/></param>
/// <param name="returnNew">if set to <c>true</c> [return new].</param>
/// <param name="fields">The fields.</param> /// <param name="fields">The fields.</param>
/// <param name="remove">if set to <c>true</c> [remove].</param>
/// <param name="returnNew">if set to <c>true</c> [return new].</param>
/// <param name="upsert">if set to <c>true</c> [upsert].</param> /// <param name="upsert">if set to <c>true</c> [upsert].</param>
/// <returns>A <see cref="Document"/></returns> /// <returns>A <see cref="Document"/></returns>
public Document FindAndModify(Document document, Document spec, Document sort, bool returnNew, Document fields, bool upsert) public Document FindAndModify(Document document, Document spec, Document sort, Document fields, bool remove, bool returnNew, bool upsert)
{ {
return _collection.FindAndModify(document, spec, sort, returnNew, fields, upsert); return _collection.FindAndModify(document, spec, sort, fields, remove, returnNew, upsert);
} }


/// <summary> /// <summary>
Expand Down

0 comments on commit 6397a0f

Please sign in to comment.