Skip to content

Commit

Permalink
FindAndModify add fields and upsert.
Browse files Browse the repository at this point in the history
  • Loading branch information
lanwin committed Sep 6, 2010
1 parent f662081 commit e09bd0d
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 17 deletions.
16 changes: 15 additions & 1 deletion source/MongoDB/IMongoCollection_1.cs
Expand Up @@ -149,8 +149,10 @@ public interface IMongoCollection<T>
/// <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>
T FindAndModify(object document, object selector, object sort, bool returnNew);
T FindAndModify(object document, object selector, object sort, bool returnNew,object fields,bool upsert);

/// <summary>
/// Entrypoint into executing a map/reduce query against the collection.
Expand Down Expand Up @@ -338,5 +340,17 @@ public interface IMongoCollection<T>
/// <param name = "document">The document.</param>
/// <param name = "safemode">if set to <c>true</c> [safemode].</param>
void Save(object 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>
/// <returns>A <see cref="Document"/></returns>
T FindAndModify(object document, object spec, object sort, bool returnNew);
}
}
27 changes: 23 additions & 4 deletions source/MongoDB/MongoCollection_1.cs
Expand Up @@ -182,7 +182,7 @@ public T FindOne(string javascriptWhere)
/// <returns>A <see cref="Document"/></returns>
/// <see cref="IndexOrder"/>
public T FindAndModify(object document, object spec, object sort){
return FindAndModify(document, spec, sort, false);
return FindAndModify(document, spec, sort, false, null, false);
}

/// <summary>
Expand All @@ -194,7 +194,21 @@ public T FindOne(string javascriptWhere)
/// <param name="returnNew">if set to <c>true</c> [return new].</param>
/// <returns>A <see cref="Document"/></returns>
public T FindAndModify(object document, object spec, bool returnNew){
return FindAndModify(document, spec, new Document(), returnNew);
return FindAndModify(document, spec, new Document(), returnNew,null,false);
}
/// <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>
/// <returns>A <see cref="Document"/></returns>
public T FindAndModify(object document, object spec, object sort, bool returnNew)
{
return FindAndModify(document, spec, sort, returnNew, null, false);
}

/// <summary>
Expand All @@ -206,8 +220,11 @@ public T FindOne(string javascriptWhere)
/// <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>
public T FindAndModify(object document, object spec, object sort, bool returnNew){
public T FindAndModify(object document, object spec, object sort, bool returnNew,object fields,bool upsert)
{
try
{
var command = new Document
Expand All @@ -216,7 +233,9 @@ public T FindOne(string javascriptWhere)
{"query", spec},
{"update", EnsureUpdateDocument(document)},
{"sort", sort},
{"new", returnNew}
{"new", returnNew},
{"fields", fields},
{"upsert", upsert}
};

var response = _connection.SendCommand<FindAndModifyResult<T>>(_configuration.SerializationFactory,
Expand Down
18 changes: 16 additions & 2 deletions source/MongoDB/Obsolete/IMongoCollection.cs
Expand Up @@ -30,7 +30,7 @@ public interface IMongoCollection
/// Gets the database.
/// </summary>
/// <value>The database.</value>
IMongoDatabase Database { get; }
IMongoDatabase Database { get; }

/// <summary>
/// Gets the meta data.
Expand Down Expand Up @@ -272,6 +272,20 @@ public interface IMongoCollection
/// </summary>
/// <param name = "document">The document.</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);
}
}
37 changes: 27 additions & 10 deletions source/MongoDB/Obsolete/MongoCollection.cs
Expand Up @@ -173,18 +173,35 @@ public Document FindAndModify(Document document, Document spec, 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 = "returnNew">if set to <c>true</c> [return new].</param>
/// <returns>A <see cref = "Document" /></returns>
/// 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>
/// <returns>A <see cref="Document"/></returns>
public Document FindAndModify(Document document, Document spec, Document sort, bool returnNew)
{
return _collection.FindAndModify(document, spec, sort, returnNew);
return _collection.FindAndModify(document, spec, sort, returnNew, null, false);
}

/// <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>
public Document FindAndModify(Document document, Document spec, Document sort, bool returnNew, Document fields, bool upsert)
{
return _collection.FindAndModify(document, spec, sort, returnNew, fields, upsert);
}

/// <summary>
Expand Down

0 comments on commit e09bd0d

Please sign in to comment.