Skip to content

Commit 072aad4

Browse files
author
rstam
committed
CSHARP-713: MongoDatabase.Eval doesn't send argument to server when there is exactly one argument.
1 parent b252bcc commit 072aad4

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

MongoDB.Driver/MongoDatabase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public virtual CommandResult DropCollection(string collectionName)
378378
/// <returns>The result of evaluating the code.</returns>
379379
public virtual BsonValue Eval(EvalFlags flags, BsonJavaScript code, params object[] args)
380380
{
381-
var argsArray = (args != null && args.Length > 1) ? new BsonArray(args) : null;
381+
var argsArray = (args != null && args.Length > 0) ? new BsonArray(args) : null;
382382
var command = new CommandDocument
383383
{
384384
{ "$eval", code },

MongoDB.DriverUnitTests/MongoDatabaseTests.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,31 @@ public void TestEvalNoArgsNoLock()
9999
}
100100

101101
[Test]
102-
public void TestEvalWithArgs()
102+
public void TestEvalWithOneArg()
103+
{
104+
var code = "function(x) { return x + 1; }";
105+
var result = _database.Eval(code, 1);
106+
Assert.AreEqual(2, result.ToInt32());
107+
}
108+
109+
[Test]
110+
public void TestEvalWithOneArgNoLock()
111+
{
112+
var code = "function(x) { return x + 1; }";
113+
var result = _database.Eval(EvalFlags.NoLock, code, 1);
114+
Assert.AreEqual(2, result.ToInt32());
115+
}
116+
117+
[Test]
118+
public void TestEvalWithTwoArgs()
103119
{
104120
var code = "function(x, y) { return x / y; }";
105121
var result = _database.Eval(code, 6, 2);
106122
Assert.AreEqual(3, result.ToInt32());
107123
}
108124

109125
[Test]
110-
public void TestEvalWithArgsNoLock()
126+
public void TestEvalWithTwoArgsNoLock()
111127
{
112128
var code = "function(x, y) { return x / y; }";
113129
var result = _database.Eval(EvalFlags.NoLock, code, 6, 2);

0 commit comments

Comments
 (0)