Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix explain

  • Loading branch information...
commit 2ffb79094085de62c2b518d983093f3a1bc921b9 1 parent dcb7912
@lanwin lanwin authored
View
15 source/MongoDB.Tests/IntegrationTests/TestCursor.cs
@@ -114,12 +114,21 @@ public void TestCanReadSmall()
}
[Test]
- public void TestExplain()
+ public void TestExplainWithSort()
{
var exp = DB["reads"].FindAll().Limit(5).Skip(5).Sort("x").Explain();
Assert.IsTrue(exp.ContainsKey("cursor"));
- Assert.IsTrue(exp.ContainsKey("n"));
- Assert.IsTrue(exp.ContainsKey("nscanned"));
+ Assert.AreEqual(9999, exp.Get("nscanned"));
+ Assert.AreEqual(10,exp.Get("n"));
+ }
+
+ [Test]
+ public void TestExplain()
+ {
+ var exp = DB["reads"].FindAll().Limit(5).Skip(5).Explain();
+ Assert.IsTrue(exp.ContainsKey("cursor"));
+ Assert.AreEqual(10, exp.Get("nscanned"));
+ Assert.AreEqual(5, exp.Get("n"));
}
[Test]
View
7 source/MongoDB/Cursor_1.cs
@@ -207,8 +207,11 @@ public ICursor<T> KeepCursor(bool value)
/// <returns></returns>
public Document Explain(){
TryModify();
- _specOpts["$explain"] = true;
+ var savedLimit = _limit;
+
+ _specOpts["$explain"] = true;
+ _limit = _limit * -1;
var explainResult = RetrieveData<Document>();
try
{
@@ -223,6 +226,8 @@ public ICursor<T> KeepCursor(bool value)
{
if(explainResult.CursorId > 0)
KillCursor(explainResult.CursorId);
+
+ _limit = savedLimit;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.