Skip to content

Commit

Permalink
Fix #CSHARP-59 FindAndModify(object document, object spec, object sor…
Browse files Browse the repository at this point in the history
…t) causes stack-overflow.
  • Loading branch information
lanwin committed Aug 27, 2010
1 parent e8b3b74 commit 20fa57e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 53 deletions.
102 changes: 51 additions & 51 deletions source/MongoDB.Tests/IntegrationTests/TestCollection.cs
Expand Up @@ -192,57 +192,57 @@ public void TestFindWhereEquivalency()
Assert.AreEqual(4, CountDocs(col.Find(explicitWhere)), "Explicit where didn't return 4 docs");
Assert.AreEqual(4, CountDocs(col.Find(funcDoc)), "Function where didn't return 4 docs");
}

[Test]
public void TestFindAndModifyReturnsOldDocument() {
IMongoCollection collection = DB["find_and_modify"];
Document person = new Document().Append("First", "Sally").Append("Last", "Simmons");
collection.Insert(person);

Document spec = new Document().Append("_id", person["_id"]);
Document loaded = collection.FindAndModify(new Document().Append("First", "Jane"), spec);

Assert.AreEqual("Sally", loaded["First"]);
}

[Test]
public void TestFindAndModifyReturnsNewDocument() {
IMongoCollection collection = DB["find_and_modify"];
Document person = new Document().Append("First", "Susie").Append("Last", "O'Hara");
collection.Insert(person);

Document spec = new Document().Append("_id", person["_id"]);
Document loaded = collection.FindAndModify(new Document().Append("First", "Darlene"), spec, true);

Assert.AreEqual("Darlene", loaded["First"]);
}

[Test]
public void TestFindAndModifySortsResults() {
IMongoCollection collection = DB["find_and_modify"];
Document doc1 = new Document().Append("handled", false).Append("priority", 1).Append("value", "Test 1");
Document doc2 = new Document().Append("handled", false).Append("priority", 2).Append("value", "Test 2");
collection.Insert(doc1);
collection.Insert(doc2);

Document update = new Document().Append("handled", true);
Document spec = new Document().Append("handled", false);
Document sort = new Document().Append("priority", -1);
Document loaded = collection.FindAndModify(update, spec, sort, true);

Assert.AreEqual(true, loaded["handled"]);
Assert.AreEqual(doc2["priority"], loaded["priority"]);
Assert.AreEqual(doc2["value"], loaded["value"]);
}

[Test]
public void TestFindAndModifyReturnNullForNoRecordFound() {
IMongoCollection collection = DB["find_and_modify"];
Document spec = new Document().Append("FirstName", "Noone");
Document loaded = collection.FindAndModify(new Document().Append("First", "Darlene"), spec, true);

Assert.IsNull(loaded, "Should return null for no document found");
}

[Test]
public void TestFindAndModifyReturnsOldDocument() {
IMongoCollection collection = DB["find_and_modify"];
Document person = new Document().Append("First", "Sally").Append("Last", "Simmons");
collection.Insert(person);

Document spec = new Document().Append("_id", person["_id"]);
Document loaded = collection.FindAndModify(new Document().Append("First", "Jane"), spec);

Assert.AreEqual("Sally", loaded["First"]);
}

[Test]
public void TestFindAndModifyReturnsNewDocument() {
IMongoCollection collection = DB["find_and_modify"];
Document person = new Document().Append("First", "Susie").Append("Last", "O'Hara");
collection.Insert(person);

Document spec = new Document().Append("_id", person["_id"]);
Document loaded = collection.FindAndModify(new Document().Append("First", "Darlene"), spec, true);

Assert.AreEqual("Darlene", loaded["First"]);
}

[Test]
public void TestFindAndModifySortsResults() {
IMongoCollection collection = DB["find_and_modify"];
Document doc1 = new Document().Append("handled", false).Append("priority", 1).Append("value", "Test 1");
Document doc2 = new Document().Append("handled", false).Append("priority", 2).Append("value", "Test 2");
collection.Insert(doc1);
collection.Insert(doc2);

Document update = new Document().Append("handled", true);
Document spec = new Document().Append("handled", false);
Document sort = new Document().Append("priority", -1);
Document loaded = collection.FindAndModify(update, spec, sort, true);

Assert.AreEqual(true, loaded["handled"]);
Assert.AreEqual(doc2["priority"], loaded["priority"]);
Assert.AreEqual(doc2["value"], loaded["value"]);
}

[Test]
public void TestFindAndModifyReturnNullForNoRecordFound() {
IMongoCollection collection = DB["find_and_modify"];
Document spec = new Document().Append("FirstName", "Noone");
Document loaded = collection.FindAndModify(new Document().Append("First", "Darlene"), spec, true);

Assert.IsNull(loaded, "Should return null for no document found");
}

[Test]
public void TestInsertBulkLargerThan4MBOfDocuments()
Expand Down
3 changes: 1 addition & 2 deletions source/MongoDB/MongoCollection_1.cs
Expand Up @@ -7,7 +7,6 @@
using MongoDB.Protocol;
using MongoDB.Results;
using MongoDB.Util;
using MongoDB.Configuration.Mapping.Model;

namespace MongoDB
{
Expand Down Expand Up @@ -183,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);
return FindAndModify(document, spec, sort, false);
}

/// <summary>
Expand Down

0 comments on commit 20fa57e

Please sign in to comment.